better way to copy and paste vba

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
794
Office Version
  1. 365
  2. 2010
finalrow = Cells(Rows.Count, "A").End(xlUp).Row



'date

Range("a2:a" & finalrow).SpecialCells(xlCellTypeVisible).Copy



''
rpt100.Activate

totalrow = Cells(Rows.Count, "A").End(xlUp).Row + 1

Range("o" & totalrow).PasteSpecial xlPasteValues

''

LML.Activate

'account
Range("b2:b" & finalrow).SpecialCells(xlCellTypeVisible).Copy



''
rpt100.Activate


Range("c" & totalrow).PasteSpecial xlPasteValues




''

LML.Activate

'inv
Range("n2:n" & finalrow).SpecialCells(xlCellTypeVisible).Copy



''
rpt100.Activate


Range("a" & totalrow).PasteSpecial xlPasteValues


''

constarntly going back and forth
 
Hi,
To remove the back and forth, you can do two things:
1) Add Application.ScreenUpdating = False at the start of the macro
(and Application.ScreenUpdating = True at the end)
2) Instead of activating the sheets, refer to the ranges with the sheet identifier. Like so (if i understand correctly the code) :
Instead of
VBA Code:
LML.Activate
'account
Range("b2:b" & finalrow).SpecialCells(xlCellTypeVisible).Copy
Do
VBA Code:
'account
LML.Range("b2:b" & finalrow).SpecialCells(xlCellTypeVisible).Copy
 
Upvote 0
Hi,
To remove the back and forth, you can do two things:
1) Add Application.ScreenUpdating = False at the start of the macro
(and Application.ScreenUpdating = True at the end)
2) Instead of activating the sheets, refer to the ranges with the sheet identifier. Like so (if i understand correctly the code) :
Instead of
VBA Code:
LML.Activate
'account
Range("b2:b" & finalrow).SpecialCells(xlCellTypeVisible).Copy
Do
VBA Code:
'account
LML.Range("b2:b" & finalrow).SpecialCells(xlCellTypeVisible).Copy

what about pasting? would this work?

RP100.Range("a" & cells(rows.count,"A").end(xlup).row+1).PasteSpecial xlPasteValues
 
Upvote 0
Rich (BB code):
RP100.Range("A" & RP100.Cells(Rows.Count, "A").End(xlUp).Row + 1).PasteSpecial xlPasteValues
If you are just pasting to the cell one down from the last cell with data in column A of RP100
 
Upvote 0

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