View Single Post
 
Old 05-20-2013, 04:43 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The basic problem with your code is that you haven't enclosed your string variables in quotes. You also haven't dimensioned your 'i' variable and your code could be made more efficient. Try:
Code:
Sub group()
Dim i As Long
For i = 1 To 6
  Select Case Range("a" & i).Value
    Case "apple": Range("C" & i).Value = 1
    Case "orange": Range("C" & i).Value = 2
    Case "banana": Range("C" & i).Value = 3
  End Select
Next i
End Sub
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote