VBA Run-time Error '1004':

MrRosco

New Member
Joined
May 12, 2016
Messages
47
Hi All,

im hoping you can assist me with this error im getting.

Run-time Error '1004': Application-Defined or Object-Defined error

the code I've used is below, and the problematic part is in bold. any help will be greatly appreciated.

Sub Save()


Dim shFrom As Worksheet, shTo As Worksheet
Dim FromLastRow As Long, ToLastRow As Long, fromstart As Long, tostart As Long, rowcount As Long, num As Long
Dim RngToCopy As Range, RngToPaste As Range
fromstart = 2
tostart = 2
rowcount = 0

With ThisWorkbook
Set shFrom = .Sheets("CONCATENATE") 'Modify as necessary.
Set shTo = .Sheets("PCF TRACKING") 'Modify as necessary.
Set shMain = .Sheets("PCF 2017")
End With


For i = 2 To 49
If Len(shFrom.Range("A" & i)) = 9 Then
Exit For
End If
Next i


FromLastRow = i - 1
tostart = shTo.Range("A" & Rows.Count).End(xlUp).Row + 1
rowcount = FromLastRow - fromstart


' MsgBox ("rowcount: " & rowcount + 1)

For fromcount = 0 To rowcount
Set RngToPaste = shTo.Range("A" & tostart + fromcount)
With shFrom
Set RngToCopy = shFrom.Range("A" & fromstart + fromcount)

'RngToCopy.Copy RngToPaste

RngToCopy.Copy
RngToPaste.PasteSpecial Paste:=xlPasteValues

Application.CutCopyMode = False

End With
Next fromcount


shMain.Range("C5,F5,F7,F8,B12:B50,E12:E50,F12:F50,L12:L50,M12:M50,N12:N50,O12:050").ClearContents

shMain.Range("K5").Select 'Change PCF No.
num = shMain.Range("K5").Value
num = num + 1
shMain.Range("K5").Value = num


End Sub



Thanks
Rosco :eek:
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi,

Looks like you have a zero where you need a letter O.

Rich (BB code):
shMain.Range("C5,F5,F7,F8,B12:B50,E12:E50,F12:F50,L12:L50,M12:M50,N12:N50,O12:050").ClearContents
 
Upvote 0
Hi,

Looks like you have a zero where you need a letter O.

Rich (BB code):
shMain.Range("C5,F5,F7,F8,B12:B50,E12:E50,F12:F50,L12:L50,M12:M50,N12:N50,O12:050").ClearContents




Thanks FormR, how much of a tit am I :)

have a good day
 
Last edited:
Upvote 0
Hi,

Looks like you have a zero where you need a letter O.

Rich (BB code):
shMain.Range("C5,F5,F7,F8,B12:B50,E12:E50,F12:F50,L12:L50,M12:M50,N12:N50,O12:050").ClearContents

Good eye!
 
Upvote 0

Forum statistics

Threads
1,215,159
Messages
6,123,348
Members
449,097
Latest member
thnirmitha

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