VBA and IF Statements

bloodmilksky

Board Regular
Joined
Feb 3, 2016
Messages
202
Hi Guys, I hope you are all well.

I was just wondering if anyone could help. I have a holiday form that has Remaing Holidays in B12, Holidays Taken In B13 and requested in E21. What I was wondering if anyone knows how I would have a MSGBOX pop up


  • If B13 EXCEEDS 25 Days or
  • If B12 & E21 EXCEED 25

Any Help would be greatly appreciated

Many thanks

Jamie
 
Try:

In a Standard Module:

Rich (BB code):
Option Explicit
  
Sub example()
  With Sheet1 '<--CodeName of sheet
    If (IsNumeric(.Range("B13").Value) Or .Range("B13").Value = vbNullString) _
       And (IsNumeric(.Range("E21").Value) Or .Range("E21").Value = vbNullString) _
       And (IsNumeric(.Range("B12").Value) Or .Range("B12").Value = vbNullString) Then
      
      If (.Range("B13").Value > 25) Or (.Range("B12").Value + .Range("E21").Value > 25) Then
        MsgBox "Nah, you don't get to ask for more time off..."
      End If
      
    End If
  End With
End Sub

Hope that helps,

Mark
 
Upvote 0
Change 'Sheet1' to the actual CodeName of the sheet possessing the Range we are looking at :-)
 
Upvote 0
still having none of it

Code:
Sub Day_Check()  With Request_Form '<--CodeName of sheet
    If (IsNumeric(.Range("B13").Value) Or .Range("B13").Value = vbNullString) _
       And (IsNumeric(.Range("E21").Value) Or .Range("E21").Value = vbNullString) _
       And (IsNumeric(.Range("B12").Value) Or .Range("B12").Value = vbNullString) Then
      
      If (.Range("B13").Value > 25) Or (.Range("B12").Value + .Range("E21").Value > 25) Then
        MsgBox "Nah, you don't get to ask for more time off..."
      End If
      
    End If
  End With
End Sub
 
Upvote 0
Rich (BB code):
Sub example()

	With ThisWorkBook.Sheets("Sheet1")

		If (.Range("B13").Value > 25) Or (.Range("B12").Value + .Range("E21").Value > 25) Then
			MsgBox "Nah, you don't get to ask for more time off..."
		Else
			MsgBox "Party hard..."
		End If

	End With

End Sub
 
Last edited:
Upvote 0
Is this something you want to happen automatically?
If so, when would you want it to run (i.e. when the workbook is opened, when certain cells are updated, etc)?
 
Upvote 0
Hi Joe4,

ideally automatically when the cells meet the criteria mentioned.


  • If B13 EXCEEDS 25 Days or
  • If B12 & E21 EXCEED 25
 
Upvote 0
@bloodmilksky

Do you want these message boxes to appear when: you open your excel file?

Yes, or no?

Do you want these message boxes to appear when: you enter a value into a certain cell?

Yes, or no?

Do you want these message boxes to appear when: you click a button?

Yes, or no?
 
Upvote 0

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