Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Compile Error

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Compile Error

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


--
__________________________________
HTH

Bob

"mypetduke" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Compile Error

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

"mypetduke" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Compile Error

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

"Bob Phillips" wrote:

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


--
__________________________________
HTH

Bob

"mypetduke" wrote in message
...
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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Compile Error

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

"Mike H" wrote:

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

"mypetduke" wrote:

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Compile Error

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



mypetduke wrote:
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bubble sort Error (Compile Error: Type Mismtach) Excel Monkey[_2_] Excel Programming 6 April 24th 09 12:16 AM
help with this error-Compile error: cant find project or library JackR Excel Discussion (Misc queries) 2 June 10th 06 09:09 PM
VBAProject name compile error, not defined at compile time Matthew Dodds Excel Programming 1 December 13th 05 08:17 PM
error message: compile error, argument not optional Pierre via OfficeKB.com Excel Programming 3 September 5th 05 03:45 PM


All times are GMT +1. The time now is 07:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"