Hi Team, Hoping you can assist me with the VBA below.
I have this sheet with many columns divided in 2 sections each section contains 13 events which are number from 1 to 13. So I am intending to bring across the events of the second section and put it to the right of the column that contains the matching heading. As the macro start bringing columns across, the original ranges should also change and I am moving it using the offset function. However I am getting a "run-time error 424: object required". Not sure why it is getting stuck there. Your assistance would be greatly appreciated
I have this sheet with many columns divided in 2 sections each section contains 13 events which are number from 1 to 13. So I am intending to bring across the events of the second section and put it to the right of the column that contains the matching heading. As the macro start bringing columns across, the original ranges should also change and I am moving it using the offset function. However I am getting a "run-time error 424: object required". Not sure why it is getting stuck there. Your assistance would be greatly appreciated
VBA Code:
Sub MovingMatchingData()
Dim rngb, rngp As Range
Set rngb = Range("v5:ah5") 'range of the second set of events
Set rngp = Range("d5:u5") 'range of the first set of events
For i = 1 To 34 'lastcolumn
For j = 1 To 13 'count of events
'Finds the event and cut the whole column and brings it across and put it to the right of the matching heading
rngb.Select
Selection.Find(What:=j, LookIn:=xlValues).Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Cut
rngp.Select
Selection.Find(What:=j, LookIn:=xlValues).Offset(0, 1).Select
Selection.Insert shift:=xlToRight
'As the columns move across the original ranges need to chance to the right so it can capture the later events otherwise the later events fall outside the range
rngb = rngb.Offset(0, 1)
rngp = rngp.Offset(0, 1)
Next j
Next i
End Sub