ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro display Msgbox when cells are empty (https://www.excelbanter.com/excel-discussion-misc-queries/144546-macro-display-msgbox-when-cells-empty.html)

Jackie

Macro display Msgbox when cells are empty
 
Hi- I want to create a macro that will display a message box when cells are
empty. For example, lets say use cell range F15:G17. If any of these cells
are empty, I want the message box to pop up. Thanks.

FSt1

Macro display Msgbox when cells are empty
 
hi
play around with something like this....
Sub countrange()
Dim cnt As Long
Dim cell As Range

cnt = 0
For Each cell In Selection ' change selection to your range
If IsEmpty(cell) Then
cnt = cnt + 1
End If
Next
MsgBox ("there are " & cnt & " empty cells in the range")
End Sub

regards
FSt1
"jackie" wrote:

Hi- I want to create a macro that will display a message box when cells are
empty. For example, lets say use cell range F15:G17. If any of these cells
are empty, I want the message box to pop up. Thanks.


JE McGimpsey

Macro display Msgbox when cells are empty
 
One way:

You don't say what should trigger the macro, so I'll assume that they're
all filled in to start, and you want to detect if they're left blank.

Put this in your worksheet code module (right-click the worksheet tab
and choose View Code):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Range("F15:G17")
If Not Intersect(.Cells, Target) Is Nothing Then
If Application.CountA(.Cells) < .Count Then _
MsgBox "Cells " & .Address(False, False) & _
" must all be filled in!"
End If
End With
End Sub


In article ,
jackie wrote:

Hi- I want to create a macro that will display a message box when cells are
empty. For example, lets say use cell range F15:G17. If any of these cells
are empty, I want the message box to pop up. Thanks.



All times are GMT +1. The time now is 09:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com