• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Range selection till the end of row

Macro should select all the cells in between the range ("B7:AH7") till the last used row.

But my macro is selecting till the end of the sheet even the blank cells.

Can anyone help me to fix this?

Code:
Sub LastRowSelection()

    Worksheets("Main Data").Select
    Range("B7:AH7").Select
    Range(Selection, Selection.End(xlDown)).Select

End Sub
 
Hi ,

The problem is your column B is blank.

If you manually carry out the same actions , you will get the same result.

Manually select the range B7:AH7 , and then press the END DOWN key ; the selection will now encompass all the rows till row 1048576.

Change the code as follows :
Code:
Sub LastRowSelection()
    Worksheets("Main Data").Select
    Range("A7:AH7").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Columns(2).Resize(, Selection.Columns.Count - 1).Select
End Sub
Narayan
 
Back
Top