Select last four columns with data?

Human_doing

Board Regular
Joined
Feb 16, 2011
Messages
137
Hi,

I wonder if anyone could please help with VBA code to find the last column of a worksheet with any cells with data and then select that row plus the three before it?

Reason is I am programming some VBA that will need to select the most recent 4 months data and copy/paste to another document. So if the worksheet is similar to this example:

Month 1 2 3 4 5
Entrys 3 4 5 6 7

I would only be looking at copying columns C-F, next month D-G etc.

Thanks
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try

Code:
Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Offset(, -3).Resize(, 4).EntireColumn.Select
 
Upvote 0
Hi , thanks for your quick reply, yes that selects the final four columns, sorry I should've been a bit more specific though, I only wish to copy the cells in the columns that contain data?

Thanks
 
Upvote 0
Maybe this

Code:
LC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
LR = Cells(Rows.Count, LC).End(xlUp).Row
Range(Cells(1, LC - 3), Cells(LR, LC)).Copy
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,445
Members
452,915
Latest member
hannnahheileen

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