Multiple VBA ifs

bibbyd01

Board Regular
Joined
Sep 10, 2008
Messages
113
Hi all

I'm stuck with some code. I'm trying to do multiple if's with an else statement but I'm stuck on this. I can't see what's wrong with my code. Basically, it should see if one of the conditions in the cells exists, if not, check the next condition, and if none exist then enter in another value.

Here's my code

Do While ActiveCell <> ""
If ActiveCell.Value = "3000000" Then
ActiveCell.Value = "SP"
If ActiveCell.Value = "3000500" Then
ActiveCell.Value = "CS"
If ActiveCell.Value = "3000600" Then
ActiveCell.Value = "PM"
Else: ActiveCell.Value = "OT"
End If
ActiveCell.Offset(1, 0).Select
Loop

On this I get an error message saying 'loop without do'. I assume I'm missing something simple here but I've not used multiple ifs before in VBA.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try

Code:
Do While ActiveCell <> ""
    If ActiveCell.Value = 3000000 Then
        ActiveCell.Value = "SP"
    ElseIf ActiveCell.Value = 3000500 Then
        ActiveCell.Value = "CS"
    ElseIf ActiveCell.Value = 3000600 Then
        ActiveCell.Value = "PM"
    Else
        ActiveCell.Value = "OT"
    End If
    ActiveCell.Offset(1, 0).Select
Loop

Alternatively you could use a Select Case statement.
 
Upvote 0
Select Case example...

Code:
    Do While ActiveCell <> ""
        Select Case ActiveCell.Value
            Case 3000000: ActiveCell.Value = "SP"
            Case 3000500: ActiveCell.Value = "CS"
            Case 3000600: ActiveCell.Value = "PM"
            Case Else: ActiveCell.Value = "OT"
        End Select
        ActiveCell.Offset(1, 0).Select
    Loop
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,673
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top