VBA Rolling data

Naimy

New Member
Joined
Jun 29, 2016
Messages
7
Hello all,

I have a data set with dates as the headers and categories in the columns. I am very new to VBA and am trying to write some code which will go to the column with the previous month (i.e June for July) and select all data below that column and copy to next column along

Can anyone please help

Thanks,
Naim
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
What row are the date headers in? Are they real dates or just text like June, July, ...?
 
Upvote 0
Months are in row 7 and yes full txt month names.

Many thanks
Try this:
Code:
Sub GetDataFromLastMonth()
'Assumes Month name headers in row 7 of active sheet
Dim Fnd As Range, LastMnth As String, ThisMnth As String
Set Fnd = Rows(7).Find(MonthName(Month(Date) - 1), , xlValues, xlWhole)
Application.ScreenUpdating = False
If Not Fnd Is Nothing Then
    Range(Cells(Fnd.Row + 1, Fnd.Column), Cells(Rows.Count, Fnd.Column).End(xlUp)).Copy Destination:=Fnd.Offset(1, 1)
Else
    MsgBox "Sorry, can't find last month's name in row 7"
End If
With Application
    .CutCopyMode = False
    .ScreenUpdating = True
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,981
Messages
6,175,771
Members
452,668
Latest member
mrider123

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