4

**Problem:**I need insert the data after last used row in the worksheet. I was able to find last used row with the following code.

ActiveSheet.Cells.(Rows.count, "D").End(xlUp).row

Now here I have to insert data next to the last used row.

Community
  • 1
  • 1
taz
  • 95
  • 1
  • 1
  • 9
  • The above method will give you the last row only for column D. If all the columns have data till the same row then the above method will work else you will have to use `.Find` to find the last row as shown [Here](http://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-vba) – Siddharth Rout May 27 '15 at 11:22

1 Answers1

7

Define lastrow as a variable first. What .row does is returns a number indicating the row, in this case the last row. The +1 moves it down by 1 cell.

Dim lastrow as Long
lastrow = Activesheet.Cells(Rows.Count, "D").End(xlUp).row + 1

Activesheet.Cells(lastrow, "D").Value = "Your Value here"
TomServo
  • 7,248
  • 5
  • 30
  • 47
iMan7
  • 133
  • 6
  • I need to add multiple data and above code replacces the last used row i want to add after that row. – taz May 27 '15 at 10:12
  • Is this with the +1 at the end of `activesheet.Cells.(Rows.Count, "D").End(xlUp).row + 1`? I forgot to add it when I first made the post. Also can you show how you're adding the data? How many cells are you adding? – iMan7 May 27 '15 at 10:20
  • It works fine. Will i be able to find last used row of sheet1 from sheet2 ?? – taz May 27 '15 at 11:35
  • Yes just replace `activesheet` with something like `Worksheets("SheetName")` – iMan7 May 27 '15 at 11:56