VBA Alert

john62290

New Member
Joined
Dec 15, 2021
Messages
26
Office Version
  1. 365
Platform
  1. Windows
I am wanting to create an alert message if one cell is left blank in tab 1 then clicking on tab 2 would make a box pop up if it is left blank.
For example, if cell h8 is supposed to have data in it in tab 1, then the user clicks on tab 2 without entering a percentage into h8, an alert pops up and says to remember to enter the percentage in H8.
Thank you for your help./
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I am wanting to create an alert message if one cell is left blank in tab 1 then clicking on tab 2 would make a box pop up if it is left blank.
For example, if cell h8 is supposed to have data in it in tab 1, then the user clicks on tab 2 without entering a percentage into h8, an alert pops up and says to remember to enter the percentage in H8.
Thank you for your help./
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window:
The script runs when you activate the sheet.

VBA Code:
Private Sub Worksheet_Activate()
If Sheets(1).Range("H8").Value = "" Then MsgBox "Sheets(1).Range(""H8"") is empty"

End Sub
 
Upvote 0
Thanks. This works for when I click on the tab but can I have it pop up when I click to another tab. When I go to tab 2 or any other tab, that is when I want it to populate.
 
Upvote 0
You can modify code to look like this and insert it in the "ThisWorkbook" module.
VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
   
     If Not ActiveSheet.Name = Sheets(1).Name And _
        Sheets(1).Range("H8").Value = "" Then _
        MsgBox "Sheets(1).Range(""H8"") is empty"
       
End Sub
 
Upvote 0
Thanks. This works for when I click on the tab but can I have it pop up when I click to another tab. When I go to tab 2 or any other tab, that is when I want it to populate.
My script should have been put in the other sheet that you want it to run in not in the sheet with Range("H8"
 
Upvote 0
You can modify code to look like this and insert it in the "ThisWorkbook" module.
VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  
     If Not ActiveSheet.Name = Sheets(1).Name And _
        Sheets(1).Range("H8").Value = "" Then _
        MsgBox "Sheets(1).Range(""H8"") is empty"
      
End Sub
That's true if you want it to run when any sheet is activated.
But I never saw where he said if any sheet. We will see
 
Upvote 0
Here is the original post:
if one cell is left blank in tab 1 then clicking on tab 2 would make a box pop up if it is left blank.
It did not say if any sheet is activated
 
Upvote 0
Ha, ha, you are right.
According to the original post we can conclude John looking strictly for tab2,
but my post was extended version after John's reply ("When I go to tab 2 or any other tab") .
 
Upvote 0
Another option is to use the deactivate event like
VBA Code:
Private Sub Worksheet_Deactivate()
   
   If Range("H8") = "" Then
      MsgBox "Please fill cell H8"
      Me.Activate
      Range("H8").Activate
   End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,913
Members
449,093
Latest member
dbomb1414

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