Excel 2002 - VBA code to insert copied cells??

  • Thread starter Thread starter rglasunow
  • Start date Start date
R

rglasunow

I would like to write a macro to copy a selected amount of data and
paste it onto the next avaliable row. However the worksheet is
continually expanding and it will not always go in the same row. Is
there a way to write the marco to paste the copied data?

I already know how to write the macro to copy all the cells but I just
need to know how to tell it to paste into the growing spreadsheet.

Thank you,
Ryan
 
and paste it onto the next avaliable row.

It would help people to help you if you explained what you mean here. An
example perhaps.
 
If I understood you, this should work. Make sure you have
something in the clipboard or it will error out. Not sure
how to check for that without using api.

Private Sub CommandButton1_Click()
' Grab the current worksheet.
Dim shtCurrent As Worksheet
Set shtCurrent = ActiveSheet
' Identify the last used row.
Dim rngLastRow As Range
Set rngLastRow = shtCurrent.UsedRange.Rows
(shtCurrent.UsedRange.Rows.Count)
' Find the first cell in the last used row.
Dim rngLastCell As Range
Set rngLastCell = rngLastRow.Cells(1, 1)
' Increment down one row to identify the target paste
cell.
Dim rngPasteTarget As Range
Set rngPasteTarget = rngLastCell.Offset(1, 0)
' Paste it.
rngPasteTarget.PasteSpecial
End Sub

HTH.
 
If column A of the destination sheet will always have data in it

worksheets("DestSheetName").Cells(rows.count,1).End(xlup)(2).Paste
 
Back
Top