Macro should copy the Col C Stock Codes on Order Form to Database Col D four times.
Then copy each set of Volumes to Database Col E.
Then copy each Destination to Database Col F.
Then copy each Delivery Date to Database Col G.
Result should be like Cols K - N in Database
Option Explicit
Dim c As Long, f As Long
Dim ws As Worksheet, ws2 As Worksheet
Sub NEWORD()
Set ws = Sheet1 ' Order Form
Set ws2 = Sheet2 'Database
'Find next free row on Database
With ws2
f = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
If f < 2 Then f = 2
'Copy Codes and Vols to Database
For c = 4 To 7
'Next line generates Runtime error 1004 -method 'range' of object '_Worksheet' failed
'Copy Stock Codes to Col D of Database
ws.Range(.Cells(23, 3), .Cells(27, 3)).Copy Destination:=.Cells(f, 4)
'Copy Stock volumes to Col E of Database
ws.Range(.Cells(23, c), .Cells(27, c)).Copy Destination:=.Cells(f, 5)
'Copy Destinations in relevant col to Col F of Database
.Range(.Cells(f, 6), .Cells(f + 4, 6)).Value = ws.Cells(14, c).Value
'Copy Scheduled Delivery Date in relevant col to Col G of Database
.Range(.Cells(f, 7), .Cells(f + 4, 7)).Value = ws.Cells(30, c).Value
'Reset f to next free row
f = f + 5
'Repeat until all Destinations complete
Next
End With
End Sub
Can't understand why it creates the RunTIme error, but hopefully someone will see the issue?
All solutions, suggestions and alternatives welcome as ever
Ochimus
Bookmarks