Most efficent code to copy a row on one sheet to a row on another

  • Thread starter gimme_this_gimme_that
  • Start date
G

gimme_this_gimme_that

I'm writing a run of the mil VBA Sub that iterates through one
worksheet and copies selected rows in another sheet. The row has 20
columns of data.

If

Dim i as Integer
Dim j as Integer
Dim s1 as Worksheet
Dim s2 as Worksheet
Dim b as Workbook
set b = ActiveWorkbook
set s1 = b.Sheets(1)
set s2 = b.Sheets(2)
i = 3
j = 7

' Most efficent code to copy 20 columns of data from s1.Rows(i) to
s2.Rows(j)
' I'd prefer not to have a For loop that iterates through 20 cells for
each row.

Thanks.
 
B

Bob Phillips

s1.Cells(i,"A").Resize(1,20).Copy s2.Cells(j,"A")

change the "A" in each part to suit.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

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