Macro Needs To Select Last Column

nikonlubber2003

New Member
Joined
Feb 20, 2003
Messages
17
Hi,

I need to create a macro that will select the last column in a worksheet. The last column can be anywhere from column "D" to column "H" on any given day. Its always different. I only need the information in the last column and then not all the information in the column, just certain cells. So the macro cannot select the entire column. Is there any code I can use for the macro to find the last column in use and copy what I need when it may be different every day? Any help would be greatly appreciated.

Thanx
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Just for starters there are several ways to identify the last column. Here are 2, and from there you can use the Cells or Columns index reference to do what you want.


MsgBox ActiveSheet.UsedRange.Columns.Count

MsgBox Range("IV1").End(xlToLeft).Column


Example:

Dim Col As Integer
Col = ActiveSheet.UsedRange.Columns.Count
Cells(1, Col).Activate

This will select the cell in row 1 of the last column being used.
 
Upvote 0
Too late for an edit, here's another method I forgot to throw in, FWIW.

Dim LastCol As Integer
LastCol = ActiveSheet.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
MsgBox LastCol
 
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,573
Members
449,173
Latest member
Kon123

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