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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Mark F

Well-known Member
Joined
Jun 7, 2002
Messages
504
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

NateO

Legend
Joined
Feb 17, 2002
Messages
9,700
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

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Just for a bit of variety :)

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

ColinKJ

Well-known Member
Joined
Jan 27, 2009
Messages
983
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

scottylad2

Well-known Member
Joined
Feb 2, 2009
Messages
1,919
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

scottylad2

Well-known Member
Joined
Feb 2, 2009
Messages
1,919
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,190,849
Messages
5,983,223
Members
439,831
Latest member
Inocente

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
Top