vba elseif not working, can someone help?

delaney1102

New Member
Joined
Aug 14, 2019
Messages
14
when i run this through using f8, it works, when i just do a straight runthrough, it goes to the end. the example i'm using should be catching in the 2nd statement. thank you!

Sub MacroName()

With Sheets("Sheet7")
.Visible = xlSheetHidden
.Activate

If Range("F7").Value = "Yes" Then
Call OtherMacro

ElseIf Range("F7").Value = "Missing Info" Then

MsgBox ("Please enter the Missing Info on Sheet5.")
Worksheets("Sheet5").Activate

ElseIf Range("NamedRange").Value = "No" Then

MsgBox ("Do not proceed.")
Worksheets("Sheet2").Activate

ElseIf MsgBox("No additional LFPS adjustments needed. Please UW as normal and upload once you have reached final rates.") Then

Worksheets("Sheet6").Activate
Worksheets("Sheet6).Unprotect "password"
Range("F4").Value = "check done" & Now()
Worksheets("Sheet6").Protect "password"


Worksheets("Sheet6").Activate


End If

End With



End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
On which sheet is the F7 the code should be looking at?
 
Upvote 0
On which sheet is the F7 the code should be looking at?
F7 is on Sheet7. NamedRange is also on Sheet7. the button to set off the macro is taking place on Sheet6

also, i just added the middle ElseIf statement and that's where my problems began. it used to work fine with just the value=Yes and the final message
 
Last edited:
Upvote 0
You have a With statement, but none of your ranges are referencing it... put a dot in front of them so they reference the object of your With statement.
 
Upvote 0
Your first If state looks like this...

If Range("F7").Value = "Yes" Then

That Range references a cell on the current worksheet, not Sheet7. Put a dot in front of it and it will then reference the object (Sheet7 in this case) of your With statement.

If .Range("F7).Value = "Yes" Then

Do that with all the Range references that need to refer to Sheet7.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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