VBA ElseIf not running

CDienst

New Member
Joined
Jul 11, 2018
Messages
31
Hello,

I think I have a fairly simple block of code here, and most of it works, but the ElseIf never happens to change the cell to V. The If before it has no problem setting the cell to H. I also tried just using an Else, but that didn't work either. I'm not getting an error or anything, and the hidden state of the rows does toggle each time it runs.

Thanks

Code:
Sub ToggleCOGSAlcohol()


Dim Alcohol As String
    Alcohol = Worksheets("DNT").Application.Range("B6").Value
            
            With Rows("54:59")
                .Hidden = Not .Hidden
            End With
 
        If Alcohol = V Then
            Range("DNT!B6").Value = "H"
        ElseIf Alcohol = H Then
     '   Else
            Range("DNT!B6").Value = "V"
        End If


End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
It looks like you're missing some quotes:

Rich (BB code):
        If Alcohol = "V" Then
            Range("DNT!B6").Value = "H"
        ElseIf Alcohol = "H" Then
     '   Else
            Range("DNT!B6").Value = "V"
        End If
 
Upvote 0
Thanks for the quick response

If I put those those in quotes, neither the If or ElseIf triggers as true.
 
Upvote 0
Then your Alcohol variable doesn't contain V or H. It looks like you have a mistake here:

Rich (BB code):
 Alcohol = Worksheets("DNT").Application.Range("B6").Value

Unless you meant to refer to whatever sheet is active when the code runs, remove the part I highlighted in blue.
 
Upvote 0
Oh, perfect. It's working now. I'll have to remove that from a few more sections, but I think it'll work everywhere.

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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