VBA Macro not working - sometimes does sometimes doesnt.

Rebeccahelp needed

New Member
Joined
Sep 7, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi.

Am using the below to copy data from E2:G2 (and down to bottom of completed cells). into Stock report - bottom of data in column A.

Sometimes it works and copies data in E to G - sometimes only what is in G???

Range("e2").Select

Dim UsdCols As Long
UsdCols = Cells(2, Columns.Count).End(xlToLeft).Column

Range("e2", Range("e" & Rows.Count).End(xlUp)).Resize(, UsdCols - 6).Copy
With Sheets("Stock Report")
.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False

Thanks for your help
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
If you want to copy columns E:G I'm not sure why you are using UsdCols?
Also, If you are using UsdCols, why are you subtracting 6?

Does this do what you want?

VBA Code:
Range("E2:G" & Range("E" & Rows.Count).End(xlUp).Row).Copy
Sheets("Stock Report").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
 
Upvote 0
How about
VBA Code:
Range("E2:G" & Range("E" & Rows.Count).End(xlUp)).Copy
Sheets("Stock Report").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
 
Upvote 0
Range("E2:G" & Range("E" & Rows.Count).End(xlUp)).Copy Sheets("Stock Report").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues Application.CutCopyMode = False
Thanks but no I get a runtime 1004 error...
 
Upvote 0
Oops missed a bit, it should be
VBA Code:
Range("E2:G" & Range("E" & Rows.Count).End(xlUp).Row).Copy
Sheets("Stock Report").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
As Peter showed.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,568
Messages
6,114,348
Members
448,570
Latest member
rik81h

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