Grouping Data in VB

davidhall80

Well-known Member
Joined
Jul 8, 2006
Messages
663
I have a column with the word "Year To Date" in row 14. However each week, it moves over one column as new data comes in. I need the previous 8 columns put into a group. In the example below. My "Year To Date" column was column N and then I grouped columns F:M. Can I put in something like this in VB. Whatever cell contains the words "Year to Date", group the previous 8 columns? Thanks



Columns("F:M").Select
Selection.Columns.Group
Range("A1").Select
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi davidhall80

Try this code:

Code:
Sub GroupCols()
Dim rC As Range

ActiveSheet.Columns.Ungroup
Set rC = ActiveSheet.Rows(14).Find("Year To Date", , xlValues, xlWhole)
rC.Offset(, -8).Resize(1, 8).EntireColumn.Group
Range("A1").Select
End Sub

Hope this solves your problem.
PGC
 
Upvote 0
Hi

I'm getting a Run Time error

Please when you get an error don't just say that there is an error. Give as much detail as you can, like I have error number xxx, with the error message "xxx", the code stops and highlights the statement with the Find, etc.

In this case please single step through the code (position the cursor inside the sub and press F8, each time you press F8 the code advances one statement).

Please report what happens. What is the statement that produces the error?

Kind regards.
PGC
 
Upvote 0

Forum statistics

Threads
1,218,809
Messages
6,144,607
Members
450,559
Latest member
kwenda farai

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