Compile Error

M

mypetduke

I have the following code and keep getting a Compile error: For without Next.
Can anyone help.

Set myrange = ActiveSheet.Range(Selection, Selection.End(xlUp))
For Each cell In myrange
If Left(cell.Value, 5) = "GL Op" Then
cell.Cut
cell.Paste ("GL Op")
End If
If Left(cell.Value, 5) = "Au Op" Then
cell.Cut
cell.Paste ("Au Op")
End If
If Left(cell.Value, 5) = "WC Op" Then
cell.Cut
cell.Paste ("WC Op")
End If
If Left(cell.Value, 5) = "CA Op" Then
cell.Cut
cell.Paste ("Au Op")
End If

End Sub
 
B

Bob Phillips

Set myrange = ActiveSheet.Range(Selection, Selection.End(xlUp))
For Each cell In myrange
If Left(cell.Value, 5) = "GL Op" Then
cell.Cut
cell.Paste ("GL Op")
ElseIf Left(cell.Value, 5) = "Au Op" Then
cell.Cut
cell.Paste ("Au Op")
ElseIf Left(cell.Value, 5) = "WC Op" Then
cell.Cut
cell.Paste ("WC Op")
ElseIf Left(cell.Value, 5) = "CA Op" Then
cell.Cut
cell.Paste ("Au Op")
End If
Next cell

End Sub
 
M

Mike H

Hi,

Maybe this

Set MyRange = Selection
For Each cell In MyRange
If Left(cell.Value, 5) = "GL Op" Then
cell.Value = Left(cell.Value, 5)
End If
If Left(cell.Value, 5) = "Au Op" Then
cell.Value = Left(cell.Value, 5)
End If
If Left(cell.Value, 5) = "WC Op" Then
cell.Value = Left(cell.Value, 5)
End If
If Left(cell.Value, 5) = "CA Op" Then
cell.Value = Left(cell.Value, 5)
End If
Next

Mike
 
M

mypetduke

Thanks Bob. You've helped me see I have a more fundamental code application
issue so I resubmitted a better question.
 
M

mypetduke

Thanks Mike You've helped me see I have a more fundamental code application
issue so I resubmitted a better question.
 
D

Dana DeLouis

Hi. Maybe not correct, but perhaps some ideas...

Sub Demo()
Dim MyRange As Range
Dim S As String
Set MyRange = ActiveSheet.Range(Selection, Selection.End(xlUp))
For Each Cell In MyRange.Cells
S = Left$(Cell.Value, 5)
Select Case S
Case "GL Op", "Au Op", "WC Op", "CA Op"
Cell = S
End Select
Next Cell
End Sub

= = = = =
HTH :>)
Dana DeLouis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top