VBA Code error 400? Copy and paste macro,(will be updatinging macro just started VBA)

Badnames

Board Regular
Joined
Jun 12, 2007
Messages
211
So here is my code, can anyone tell me why I'm getting an x400 error?

The code is supposed to take from the sheet "Input" and copy the selection into "Sheet1" if it is "Product1" in cell B21-b120.

Application.ScreenUpdating = False
Dim i As Long
Dim sheet1count As Integer
i = 21
sheet1count = 0
Do While i <= 120

Worksheets("Input").Activate
Range("B" & i).Select
If Range("B" & i) = "Product1" Then
Range(("B" & i), ("z" & i)).Select
Application.CutCopyMode = False
Selection.Copy
Worksheets("Sheet1").Activate
Range("A" & (3 + sheet1count)).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
sheet1count = sheet1count + 1
End If

SkipLine:
i = i + 1
Loop
Application.ScreenUpdating = True
Worksheets("Sheet1").Activate
MsgBox ("Done!")

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Figured it out, it was because the code was on a sheet, not a module.

Edit*** well at least it fixed the problem for now. Not sure if it was a permanent fix. I also noticed when I had another workbook open (and the code was in the worksheet not a module) it was copying to sheet1 in the first workbook open and then ending immedietely rather than copying into the workbook I was working in.
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,473
Members
452,915
Latest member
hannnahheileen

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