0

I am trying to select the bottom most right cell in my field of data. I have a 20x20 grid of data and need to find the last column that it would go down to find the last row that has data. I am having trouble using active cell function with in my second line of code.

 Sub Add

      Range("A2").End(xlToRight).Select
      Range("A2").End(xlDown).Select

 End Sub
Mark Austin
  • 129
  • 2
  • 3
  • 13

2 Answers2

1
Sub Add
    ActiveCell.SpecialCells(xlCellTypeLastCell).Select
End Sub
LS_ᴅᴇᴠ
  • 10,823
  • 1
  • 23
  • 46
  • This works in a blank excel file but when i try to use it in my current project it does not work. It say the blank file is BF156 that is way off. Is there any way to use the code above. I know that is not the best way but atleast it will work with how i have set um my other VBA code – Mark Austin Jul 29 '13 at 16:24
1

If you want to fix your current code:

Sub Add
  Range("A2").End(xlToRight).End(xlDown).Select
End Sub

but it will fail (stop short) if there are any blank cells going across or down.

See the page linked by Head of Catering for better ways to do this.

Andy G
  • 19,232
  • 5
  • 47
  • 69