Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Karina K patni   on Mar 11 In MS Office Category.

  
Question Answered By: Jake Evans   on Mar 11


Try:

Sub last_row()

'Dim lastrow As Range
Sheets("sheet1").Select
lastrow = Range("g3:m3").End(xlDown).Row - 1
Range("G3:M" & lastrow).Select

End Sub


Changes made are:
1.The name of the sub; you named the sub the same as a variable  name.
2.The commenting out of the Dim line; you defined lastrow as a range
then you try 2 lines later to assign a number to it. You don't need
it.
3.Changed
Range("g3" & lastrow).Select
to
Range("G3:M" & lastrow).Select


You could tweak it a bit more by changing the line:
lastrow = Range("g3:m3").End(xlDown).Row - 1
to
lastrow = Range("g3").End(xlDown).Row - 1
since xl won't look in multiple columns for the last cell, only one,
the active cell column. Replace the G of G3 with the column letter of
the column you want to find the last entry of.

Share: 

 
 
Didn't find what you were looking for? Find more on Select Range, less last row Or get search suggestion and latest updates.


Tagged: