Basically what I’m doing is I have data in columns A-I and I’m trying to copy out data [Columns D-G] by their value in D. In this loop I’m looking for when the entry in D says “1CME Cash-Settled Butter”.
I then starting in column K (=11) I paste it. Then I stack the rows.
The loop starts over and starts looking for a different value.
My problem is that I’ve ran the code fine for many runs. I haven’t changed the code since, but now I’m getting Run-Time Error Type ’13’ Mismatch. Is there someway to fix this or write new code?
I’m just learning VBA!
Thanks!
iRow = 2
For Each i In Range("D2:D200")
If i.Value = "1CME Cash-Settled Butter" Then
Range(i.Offset(0, 0), i.Offset(0, 3)).Copy
Cells(iRow, 11).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
iRow = iRow + 1
End If
Next i
iRow = 30
For Each i In Range("D2:D200")
If i.Value = "-1CME Cash-Settled Butter" Then
Range(i.Offset(0, 0), i.Offset(0, 3)).Copy
Cells(iRow, 11).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
iRow = iRow + 1
End If
Next i
Change i.Value
to i.Text
. You don’t want the Value, because you’re comparing it to an integer. You want to check the String, and using i.Text
will do that.
You can also cstr(i.Value)
, but that’s not the best way to do it.