1004 Error Copying and Pasting Range

stinkingcedar

New Member
Joined
May 2, 2016
Messages
23
Hi everyone,

I am attempting to construct a code that will cycle through all sheets in a workbook (except for the first two), finding a range in each, copying that range and then pasting it to a specific workbook based on a case. I keep getting an error message.

Code:
Public Sub newcopy()

Dim WSCount As Long, StartCellRow As Long, i As Long
Dim sht As Worksheet
Dim region As String

region = Range("D1").Text

WSCount = Worksheets.Count-2
Application.ScreenUpdating = False

For i = 3 to WSCount + 2[INDENT]Set sht = Sheets(i)
Sheets(i).UsedRange
StartCellRow = sht.Cells.Find("keyphrase", LookAt:=Whole,_
LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection_
:=xlNext).Row + 1
sht.Range(Cells(StartCellRow, 6), Cells(StartCellRow + 29,_
27)).Copy

Select Case region
[/INDENT]
[INDENT=2]Case Is = "A"
Sheets("A").Cells((30*(i-1))+4,6).PasteSpecial (xlPasteValues)

Case Else
Sheets("I").Cells((30*(i-1))+4,6).PasteSpecial (xlPasteValues)

[/INDENT]
[INDENT]End Select[/INDENT]
Next i

End Sub

The specific line that keeps getting the 1004 error message is this one:

Code:
sht.Range(Cells(StartCellRow, 6), Cells(StartCellRow +29,27)).Copy
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Just a guess as I haven't read through the rest of the code but do you get an error if you change that line to

Code:
sht.Range([COLOR="#FF0000"]sht.[/COLOR]Cells(StartCellRow, 6), [COLOR="#FF0000"]sht.[/COLOR]Cells(StartCellRow +29,27)).Copy
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

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