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
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

pgc01

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

Watch MrExcel Video

Forum statistics

Threads
1,114,675
Messages
5,549,363
Members
410,911
Latest member
AniEx
Top