Last empty row to last data row

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi anyone,

How could I change the following code so that it copies the cell content from active sheet to the sheet data's; starting from last empty row to last data row.
Code:
Sub Last()
Range("C1").Copy Destination:=Sheets("Dat").Range("B" & r & ":B")
End Sub

Any help on this would be appreciated.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
adamsm,


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


Code:
Option Explicit
Sub Last()
' hiker95, 04/22/2011
' http://www.mrexcel.com/forum/showthread.php?t=545489
Dim r As Long
r = Sheets("Dat").Range("B" & Rows.Count).End(xlUp).Offset(1).Row
ActiveSheet.Range("C1").Copy Destination:=Sheets("Dat").Range("B" & r)
End Sub
 
Upvote 0
Not totally clear what you mean. But I am assuming you have a range on the active sheet of unknown number of rows, which you want to copy to the Sheet("data") below the last row. Or do you only want to copy one cell to the row below the last row?

Option 1 (larger number of rows attached to current selected cell in active sheet:
Code:
Sub Last()
   Dim lRows as long, lDest as long
 
   lDest = Sheets("Data").Range("B1").CurrentRegion.Rows.Count
   lRows = Activesheet.ActiveCell.CurrentRegion.Rows.Count
 
   with ActiveCell
       Range(Cells(.Row,.Column),Cells(.Row+lRows-1,.Column)).Copy _
            Destination:=Sheets("Data").Range("B" & lDest)
   end with
end Sub

Option 2 (Copy only current selected cell)
Code:
Sub Last()
   Dim lDest as long
 
   lDest = Sheets("Data").Range("B1").CurrentRegion.Rows.Count
   lRows = Activesheet.ActiveCell.CurrentRegion.Rows.Count
 
      ActiveCell.Copy _
            Destination:=Sheets("Data").Range("B" & lDest)
   end with
end Sub
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top