Need help with an If Statement in VBA.

figuare9

Board Regular
Joined
Oct 23, 2017
Messages
118
Looking to do something like this on a Command Button


If Range("N9").Value = Range("E8").Value Then

'Run another if statement code here'
If Range("N9") = "" Or Range("O9") = "" Or Range("P9") = "" Then
'Do Nothing'
'If Cut Section, Length, And Width Is NOT Empty, Message Box Error'
ElseIf Range("P8") > Range("G8") Or Range("O8") > Range("F8") Then
MsgBox "Your Cut Dimensions Do No Fit Inside The Section You Specified"

If Range("N9").Value = Range("E9").Value Then

'Run another if statement code here'
If Range("N9") = "" Or Range("O9") = "" Or Range("P9") = "" Then
'Do Nothing'
'If Cut Section, Length, And Width Is NOT Empty, Message Box Error'
ElseIf Range("P8") > Range("G8") Or Range("O8") > Range("F8") Then
MsgBox "Your Cut Dimensions Do No Fit Inside The Section You Specified"



Basically... I want to run an "IF" after an "IF" "Depending on what the value is...

hmm.. Try to word it the best I can.. haha..

If the value of my N9 = the value of E8, I want to run my if statements to follow.
If the value of my N9 = the value of E9, I'd like to run a different set of if statements to follow.



I want to click the button and have it check which value N9 ='s. Then It needs to run more if statements depending on the conditions I have. I thought I could do it with directives like this..

Code:
[COLOR=#007D9A][FONT=Consolas]#Const CustomerNumber = 36[/FONT][/COLOR][COLOR=#007D9A][FONT=Consolas]#If CustomerNumber = 35 Then[/FONT][/COLOR][COLOR=green][FONT=Consolas]' Insert code to be compiled for customer # 35.[/FONT][/COLOR][COLOR=#007D9A][FONT=Consolas]#ElseIf CustomerNumber = 36 Then[/FONT][/COLOR][COLOR=green][FONT=Consolas]' Insert code to be compiled for customer # 36.[/FONT][/COLOR][COLOR=#007D9A][FONT=Consolas]#Else[/FONT][/COLOR][COLOR=green][FONT=Consolas]' Insert code to be compiled for all other customers.[/FONT][/COLOR][COLOR=#007D9A][FONT=Consolas]#End If

[/FONT][/COLOR]
But I'm having some issues.. Any help?

I'm still googling the hell out of this.. Could I use something like

If [Condition] Then
If [Condition] Then
[Condition]
Exit sub?
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Not sure what you're trying to do, but does a select case statement help you
Code:
   Select Case Range("N9").Value
      Case Is = Range("E8").Value
         MsgBox "E8"
      Case Is = Range("E9").Value
         MsgBox "E9"
      Case Else
         MsgBox "no Match"
   End Select
 
Upvote 0
My apologies.. This one is probably really easy, but hard for me to explain.. ha!

Let me try one more time here. :)

(Simplified)
If N9 = 1, Then run an If statement.
If N9 = 2, Then run an different If statement.

So when I click the button, I want it to check if N9 = the value of E8, or E9. And run different if statements depending on what the Value of N9 is.

Does N9 = E8? Then

Code:
If [Condition] Then
MsgBox "N9 = E8"
End If

IF It doesn't equal E8, then check if it equals E9.

Does N9 = E9? Then

Code:
If [Condition] Then
MsgBox "N9 = E9"
End If
 
Last edited:
Upvote 0
Simply replace the msgboxs I used in the select case with your code & try it.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,700
Messages
6,126,279
Members
449,308
Latest member
VerifiedBleachersAttendee

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