Advertisement
dave3009

ETGP220723

Jul 23rd, 2022
1,787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'https://www.facebook.com/groups/659225117560345/permalink/2494806137335558
  2. 'I have a monthly timesheet where different speadsheet for each team member.
  3. 'Need some help experts. e.g Jul_22_SA, Jul_22_AN (FYI: sheet name format Mmm_YY_INITIALS).
  4. 'Each sheet consists of 2 table ranges, one for Billable (B) activitie the other one is for Nonbillable (NB) activities
  5. 'Is there a way i have the table name alligned with the sheet name automaticaly like JUL22SAB and JUL22SANB.
  6.  
  7. Sub RenameTables()
  8. Dim tName As String
  9. Dim sht As Worksheet
  10. 'Loop over the worksheets
  11. For Each sht In ThisWorkbook.Worksheets
  12.     With sht
  13.         ' OP states each sheet has 2 tables, billable(B) & non-billable(NB)
  14.        ' test that the sheet has exactly 2 tables
  15.        If .ListObjects.Count = 2 Then
  16.             'sheet name is in format Mmm_yy_XX
  17.            'table name format required MMMYYXXB/NB
  18.            tName = UCase(Replace(.Name, "_", "")) 'Convert sheet name
  19.            .ListObjects(1).Name = tName & "B" ' billable table
  20.            .ListObjects(2).Name = tName & "NB" ' non-billable table
  21.        End If
  22.     End With
  23. Next sht
  24. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement