Find Last Used Column In Row ?

ColinKJ

Well-known Member
Joined
Jan 27, 2009
Messages
983
Hi,

Can anyone please help.

I frequently use

row = Sheets(1).Range("A65536").End(xlUp).Row

to find the last used cell in a column

Can someone tell me the equivalent to find the last cell used in a row.

ColinKJ
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How about something like the code below to find the last column?

Code:
intLastColumn = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column

Mark
 
Upvote 0
Hi Colin,

In a similar manner, turn on your Macro Recorder, go to the farthest cell possible on the right side of your Spreadsheet (pre 2007, column IV), and hit End, then your left cursor. Turn off your recorder, and you have said syntax. :)
 
Upvote 0
Just for a bit of variety :)

Code:
LastCol = ActiveSheet.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
 
Upvote 0
Thanks a lot guys.

Always more thank one way of skinning cat.

(Sorry cat lovers it's only a saying.)
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
ColinKJ
 
Upvote 0
If you know just now where the last cell with data is, start recording and place your cursor in the same column at the top and hit control and down arrow to get to the bottom of the data set then do the same again to get to the bottom of the page. Now use control and UP arrow, which will make your selection jump back into the last cell with data in it, switch to the relative button and move to one cell below then stop recording. as long as your data stays in the same column, then running that macro will always bring you to the cell one below the last one with data in. I'm sure the same trick will work with the last rows but some of the more experienced macro users will know.
be sure to have the same cell as your starting point when running the macro
 
Upvote 0
Sub Macro7()
'
' Macro7 Macro
'

'
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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