-1

How can I modify

XLApp.Range("A1:K1" & LastRow).Copy

if I want to copy the A1:K1 untill the last row there is data in one of the cells in the selected area . Sorry for my poor English.

zx81
  • 41,100
  • 9
  • 89
  • 105
user3619557
  • 1
  • 1
  • 2
  • possible duplicate of [Error Finding Last Used cell In VBA](http://stackoverflow.com/questions/11169445/error-finding-last-used-cell-in-vba) – RubberDuck May 09 '14 at 14:24

2 Answers2

1
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row 

will give you the last row in column no 1 ("A"). For last row in column k, you need to use 11 in place of 1.

Peekay
  • 238
  • 11
  • 21
0

The code below shows a generic way to do that:

Range(Range("A1", Range("A1").End(xlToRight)), Range("A1", Range("A1").End(xlDown))).Rows.Count

you can change the A1 reference to other if you want. The codes copy a range the starts from A1 to right and from right to down.

cantoni
  • 2,912
  • 2
  • 17
  • 24