Sub Grouping2()
Dim aText1R As String
Dim aText2R As String
Dim aText1 As String
Dim aText2 As String
LastColumn = ActiveSheet.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Column
a = 0
b = 0
For i = 1 To LastColumn
SText = Cells(2, i).Value
nChar = InStr(SText, "'")
If nChar > 0 Then
aText = Split(SText, "'")
aText1R = aText(0)
aText2R = aText(1)
aText1 = Len(aText1R)
aText2 = Len(aText2R)
If aText1 = 3 And aText2 = 2 Then
If a = 0 Then
a = i 'This captures the 1st instance of a column header with an apostrophe in it
Else
b = i 'This captures the last instance of a column header with an apostrophe
End If
Else
If a <> 0 And b <> 0 Then
Range(Columns(a), Columns(b - 1)).Group 'Note the b-1 is being done so that the last month's/latest month's data is not hidden
Range(Columns(a), Columns(b - 1)).Hidden = True 'Note the b-1 is being done so that the last month's/latest month's data is not hidden
a = 0
b = 0
Else
End If
End If
Else
If a <> 0 And b <> 0 Then
Range(Columns(a), Columns(b - 1)).Group
Range(Columns(a), Columns(b - 1)).Hidden = True
a = 0
b = 0
Else
End If
End If
Next i
End Sub
Sub Grouping3()
Dim aText1R As String
Dim aText2R As String
Dim aText1 As String
Dim aText2 As String
LastColumn = ActiveSheet.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Column
a = 0
b = 0
For i = 1 To LastColumn
SText = Cells(3, i).Value
nChar = InStr(SText, "'")
If nChar > 0 Then
aText = Split(SText, "'")
aText1R = aText(0)
aText2R = aText(1)
aText1 = Len(aText1R)
aText2 = Len(aText2R)
If aText1 = 3 And aText2 = 2 Then
If a = 0 Then
a = i 'Captures the 1st instance of a column heading that contains an apostrope
Else
b = i 'Captures the last instance of a column heading that contains an apostrophe
End If
Else
If a <> 0 And b <> 0 Then
Range(Columns(a), Columns(b - 1)).Group
Range(Columns(a), Columns(b - 1)).Hidden = True
a = 0
b = 0
Else
End If
End If
Else
If a <> 0 And b <> 0 Then
Range(Columns(a), Columns(b - 1)).Group 'This creates a group out of a collection of columns
Range(Columns(a), Columns(b - 1)).Hidden = True
a = 0
b = 0
Else
End If
End If
Next i
End Sub