Conditional Message Box

danchu1

New Member
Joined
Mar 20, 2014
Messages
4
Hi, thanks for all help in advance!

I need help writing a script in VBA which is conditional on an active cell being either blank or with characters

i.e if specific cell (A1) is blank then Message Box appears otherwise do nothing

Thanks!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I'm guessing Andrew presumed you would know to do this.
Name the sub whatever you want
Copy and paste in the sheet module. You can assign it to a button to run.

If you want it to run by its self, post back and we can put it in an event macro.

Code:
Option Explicit

Sub Danchu1()
If Range("A1").Value = "" Then
    MsgBox "Blank"
End If
End Sub

Howard
 
Upvote 0
Thank you, yes I'd like to know how to make it run by itself in an event macro.

Really appreciate your help
 
Upvote 0
Copy and paste in the sheet module.

Change B1 in any manner, type an "X" into it and you will get the message box. Now delete the "X", see message again.
Put an "X" in A1 and do the same routine with B1. No message boxes.

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$B$1" Or Target.Cells.Count > 1 Then Exit Sub
If Range("A1").Value = "" Then
    MsgBox "Blank"
End If
End Sub

There are many Worksheet_Event macros already named and stored in the sheet VBA Editor.

Howard
 
Upvote 0
Hmm, not working

Sorry to be a pain

The active cell is u59 if the cell is blank, then a message box should appear, if it is not blank then the message box should not.

Will be looking for classes on Excel VBA, if you can recommend any in NYC it would be great

Thanks,
danchu1
 
Upvote 0
Then go back to Andrews original post and my follow up. Change A1 to U59.

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("U59").Value = "" Then
    MsgBox "Blank"
End If
End Sub

Don't know any classes in NYC, but you could google "Excel vba code classes New York City".

I would suspect you would get huge list.

Howard
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,050
Members
449,206
Latest member
Healthydogs

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