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
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
