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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,887
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
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,887
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
 

davidhall80

Well-known Member
Joined
Jul 8, 2006
Messages
663
My mistake your code was correct. I had my YTD in the wrong column. Thanks!!!!!!!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,128
Messages
5,857,531
Members
431,884
Latest member
Gcmoore63

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
Top