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
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,118
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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
 

CDienst

New Member
Joined
Jul 11, 2018
Messages
31
Thanks for the quick response

If I put those those in quotes, neither the If or ElseIf triggers as true.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,118
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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.
 

CDienst

New Member
Joined
Jul 11, 2018
Messages
31
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
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,118
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Glad to help. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,957
Messages
5,599,046
Members
414,281
Latest member
Engjamal2021

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
Top