View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Last Used Cell in a row??

For row #13, for example:

Sub findit()
MsgBox (Cells(13, Columns.Count).End(xlToLeft).Column)
End Sub


OK, that I have understand myself, at what place the desired row
number is to be specified :)


I rearranged the relevant parts of the posted messages for clarity. Notice
that Gary''s Student started by saying "for row #13" and then in his posted
code uses 13 as the first argument for the Cells Range object? Just replace
the 13 with the row you want to check. If it helps you any, you can turn
this code into a function to make your calling it simpler...

Function LastColumn(RowNumber As Long) As Long
LastColumn = Cells(RowNumber, Columns.Count).End(xlToLeft).Column
End Function

This way, assuming the function is in scope, you can use it directly in your
code. For example

LastColumnInRow5 = LastColumn(5)

or

MsgBox "There are " & LastColumn(5) & " columns being used in row 5."

Rick