Code to copy cell values from one sheet to another

  • Thread starter Talat via OfficeKB.com
  • Start date
T

Talat via OfficeKB.com

Hi,

Can anybody help me with this?

I recorded a macro which copies cells value from one open excel file into
another excel file where it needs to find the lasy used row, and then copy
into cells in the row below it. But the resultant VBA code references actual
cell values eg Range("A15658").Select which does not work because next time
the macro is run it should be +1

steps might be
open worksheet a and Sheets
Copy from
sheetA, row 10, columnB
to worksheetB
last used row+1, column A

Copy from
sheetA, row 10, columnD
to worksheetB
last used row+1, column B ..... etc

Once I sort this out, I have one more query. If I can't sort it out myself,
would like to get back to you or the forum again.

Many thanks.

Talât
 
G

Gary''s Student

This will copy from Sheet1 cell D10 to Sheet2 first available cell in column B:

Sub CopyDemo()
Dim s1 As Worksheet, s2 As Worksheet
Dim rSource As Range, rDest As Range
Set s1 = Worksheets("Sheet1")
Set s2 = Worksheets("Sheet2")
Set rSource = s1.Range("D10")
n = s2.Cells(Rows.Count, 2).End(xlUp).Row + 1
Set rDest = s2.Range("B" & n)

rSource.Copy rDest

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top