Else Without If

  • Thread starter Thread starter T De Villiers
  • Start date Start date
T

T De Villiers

Get the above message for this portion of code,
Many thanks for your help

Sub leng()

For i = 14 To 7
If Len(Cells(4, i)) = 5 Then Cells(4, i) = "J" & Cells(4, i)
Else
If Cells(4, i) = 123 Then Cells(4, i) = "R" & Cells(4, i)
Else
If Cells(4, i) = 124 Then Cells(4, i) = "R" & Cells(4, i)
Else
If Cells(4, i) = 128 Then Cells(4, i) = "R" & Cells(4, i)
Else
If Cells(4, i) = 148 Then Cells(4, i) = "R" & Cells(4, i)
Else
If Cells(4, i) = 157 Then Cells(4, i) = "R" & Cells(4, i)
Else
If Cells(4, i) = 161 Then Cells(4, i) = "Q" & Cells(4, i)
End If
Next

End Sub
 
Try this...

Sub leng()
Dim i As Integer
For i = 14 To 7 Step -1
If Len(Cells(4, i)) = 5 Then
Cells(4, i) = "J" & Cells(4, i)
ElseIf Cells(4, i) = 123 Then
Cells(4, i) = "R" & Cells(4, i)
ElseIf Cells(4, i) = 124 Then
Cells(4, i) = "R" & Cells(4, i)
ElseIf Cells(4, i) = 128 Then
Cells(4, i) = "R" & Cells(4, i)
ElseIf Cells(4, i) = 148 Then
Cells(4, i) = "R" & Cells(4, i)
ElseIf Cells(4, i) = 157 Then
Cells(4, i) = "R" & Cells(4, i)
ElseIf Cells(4, i) = 161 Then
Cells(4, i) = "Q" & Cells(4, i)
End If
Next

End Sub
 
Try this

Sub leng()
Dim i As Integer
For i = 14 To 7 Step -1
Select Case Cells(4, i).Value
Case 5: Cells(4, i) = "J" & Cells(4, i)
Case 123, 124, 128, 148, 157: Cells(4, i) = "R" & Cells(4, i)
Case 161: Cells(4, i) = "Q" & Cells(4, i)
End Select
Next

End Sub


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"T De Villiers" <[email protected]>
wrote in message
news:[email protected]...
 

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

Back
Top