Hi all
Trying to have Excel move a pieces of data from a sheet called import to another sheet called format, however the below code comes up with either
"PasteSpecial method of range class failed" or "Cut method of Range class failed" when it tries to copy inside the select case portion.
I've put the failing code in Red/Bold font
any ideas?
Cheers
Trying to have Excel move a pieces of data from a sheet called import to another sheet called format, however the below code comes up with either
"PasteSpecial method of range class failed" or "Cut method of Range class failed" when it tries to copy inside the select case portion.
I've put the failing code in Red/Bold font
any ideas?
Cheers
Code:
Sub format()
Application.ScreenUpdating = False
Dim fmt As Worksheet, inp As Worksheet, v0 As Worksheet
Set fmt = Worksheets("Format")
Set inp = Worksheets("import")
Set v0 = Worksheets("Parameters")
inp.Activate
''-----------------------------------------
'Find and insert Deliver to address
Range("B1:B20").Find("Deliver To", LookIn:=xlValues, MatchCase:=False).Activate
ActiveCell.Offset(0, 1).Activate
If IsEmpty(ActiveCell) = True Then
ActiveCell.Offset(1, 0).Activate
End If
Dim dt1, dt2, dt3 As Variant
dt1 = Application.VLookup(ActiveCell.Value, Worksheets("Parameters").Range("A:D"), 2, False)
dt2 = Application.VLookup(ActiveCell.Value, Worksheets("Parameters").Range("A:D"), 2 + 1, False)
dt3 = Application.VLookup(ActiveCell.Value, Worksheets("Parameters").Range("A:D"), 2 + 2, False)
'VLookup Error Handling
If IsError(dt1) Then
dt1 = ActiveCell.Value
dt2 = "(Address Not programmed)"
dt3 = ""
End If
With fmt
.Range("C11").Value = dt1
.Range("C12").Value = dt2
.Range("C13").Value = dt3
End With
''-----------------------------------
'Body Content Insertion
Dim rng As Range, rng2 As Range
Dim mr, r1 As Long, r2 As Long
Dim rstart, rend As Long
'sets maximum row scan
mr = v0.Range("K1").Value
For r1 = 1 To mr Step 1
'finds the beginning of each POs by looking for the *** START OF PURCHASE ORDER - *** part
If InStr(1, LCase(Range("C" & r1)), "start of purchase order") > 0 Then
rstart = r1
'get the last row of that section
For r2 = r1 To mr Step 1
If InStr(1, LCase(Range("C" & r2)), "end of purchase order") > 0 Then
rend = r2
Exit For
End If
Next r2
For rstart = rstart To rend Step 1
Dim onumb, ostat, over, odate, ddate As String
Select Case Range("B" & rstart).Value
[COLOR=#b22222] Case "Order Number:"
[B] Range("C" & rstart).Cut Destination:=(fmt.Range("F14"))[/B][/COLOR]
Case "Order Status:"
Range("C" & rstart).Cut Destination:=(fmt.Range("F15"))
Case "Order Version:"
Range("C" & rstart).Cut Destination:=(fmt.Range("F10"))
Case "Order Date:"
Range("C" & rstart).Cut Destination:=(fmt.Range("F11"))
Case "Delivery Date:"
Range("C" & rstart).Cut Destination:=(fmt.Range("F12"))
Case "Item Number"
rstart = rstart + 1
itemmove (rstart)
End Select
Next rstart
End If
Next r1
Debug.Print onumb
Debug.Print ostat
Debug.Print over
Debug.Print odate
Debug.Print ddate
Application.ScreenUpdating = True
End Sub
Last edited: