Grouping data inbetween columns

davidhall80

Well-known Member
Joined
Jul 8, 2006
Messages
663
I have 10 columns of data. In the middle of those columns somewhere are the "Weekly Sales" column and an "Employee" column. I need the columns inbetween "Weekly Sales" and "Employee" grouped and hidden.(not including "Weekly Sales and "Employee" columns in the grouping). When I run my Macro, I do not know which columns the data will be in. All I know is that column headings are in row one. Any help will be appreciated. Thanks!!!!!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try this:
Code:
Sub Hide()
Dim rCell As Range

For Each rCell In Range(Rows("1:1").Address)
    If rCell = "Weekly Sales" Then
        counter = 1
        Do Until rCell.Offset(0, counter) = "Employee"
            rCell.Offset(0, counter).EntireColumn.Hidden = True
            counter = counter + 1
        Loop
    End If
Next

End Sub
Dufus
 
Upvote 0
Hi
try
Code:
Sub test()
Dim WeeklySales As Range, Employee As Range
On Error Resume Next
Set WeeklySales = Rows(1).Find("Weekly Sales").Offset(,1)
Set Employee = Rows(1).Find("Employee").Offset(,-1)
Range(WeeklySales,Employee).EntireColumn.Hiden = True
End Sub
 
Upvote 0
Thanks!!! It worked...One more question. Lets say I want two seperate groupings beween those two columns. The first grouping would be the last 4 columns before "Employee" (not including "Employee"). The second grouping would be the rest of the columns in between "Weekly sales" and "Employee" (also not including "weekly sales" in the grouping). I guess in VB terms, the second grouping would be--the count of columns in between "Weekly Sales and "Employee" minus 4. Thanks a bunch !!! This is great
 
Upvote 0
Hi
try
Code:
Sub test()
Dim WeeklySales As Range, Employee As Range
On Error Resume Next
Set WeeklySales = Rows(1).Find("Weekly Sales").Offset(,1)
Set Employee = Rows(1).Find("Employee").Offset(,-1)
x = Range(WeeklySales,Employee).Columns.Count + 1
Employee.Offset(,-3).Resize(,4).EntireColumn.Hidden = True
WeeklySales.Resize(,x-4+1).EntireColumn.Hidden = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,556
Messages
6,114,284
Members
448,562
Latest member
Flashbond

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top