Warn if data is in range

P

Pat

I need a warning to appear when a user enter a value into A1, if there is a
value in any cell in the range B1:T1

Any one got a solution?
Thanks
Pat
 
B

Bob Phillips

Hi Pat,

One way

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
If .Address = "$A$1" Then
If Application.CountA(Range("B1:T1")) > 0 Then
MsgBox "Data in B1:T1"
End If
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
O

Ola

Try this:
Goto cell A1. Select menu: Data > Validation...
Tab: Settings Allow: Custom Formula: =COUNT(B1:T1)=0
Tab: Error Alert Title: Error Values present in B1:T1

Done!

Ola Sandstrom
 
J

JulieD

Hi Pat

you can code a worksheet_change even to check to see if there is anything in
B1:T1 when data is entered in A1 - e.g.

----
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" And Target.Value <> "" Then
If
Application.WorksheetFunction.CountIf(Sheets("Sheet3").Range("B1:T1"), "*")
MsgBox "Range B1:T1 is not empty"
End If
End If
End Sub
---

to use the code, right mouse click on the sheet that you want to run the
code against and choose view code
copy & paste the above directly into the right hand side screen - if you get
any red lines, click at the end of the line and press the delete key - this
should fix up any line break problems.
change "Sheet3" to the name of your sheet
use alt & f11 to switch back to your worksheet and test

Hope this helps
Cheers
JulieD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top