Displaying an error message

pells

Active Member
Joined
Dec 5, 2008
Messages
361
Is it possible to display an error message box if the following criteria is met on my active sheet:

If cell range A1:A88 has something in any of the cells and if cells H1:H88 is blank, then show the error message, otherwise, do nothing?

Many thanks for taking the time to read my post and any responses with help or guidance would be much appreciated.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Code:
Sub ErrMsg()
    If WorksheetFunction.CountA(Range("A1:A88")) > 0 And WorksheetFunction.CountA(Range("H1:H88")) = 0 Then
       MsgBox "Error message", vbCritical, "Error"
    End If
End Sub
 
Upvote 0
You could add data validation to a1:a88 using a Custom allow with the formula:
=NOT(AND(COUNTA(A4:A91)>0,COUNTA(H4:H91)=0))
and then set the alert to Warning rather than stop.
 
Upvote 0
Perhaps something like this?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A88")) Is Nothing Then
    If Len(Target.Offset(0, 7).Value) = 0 Then
        MsgBox "Please enter a value in column H"
        Target.Offset(0, 7).Select
    End If
End If
End Sub
To use this code, right click on the sheet tab you want this to run on, and click view code. Paste the above code in the window that pops up.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

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