#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 57
Default warning message

HI, I want to display a warning message in column J whenever the number
exceeds 2.

At the moment I got something like this....

Dim ErrorMSG As String

If Application.CountIf(Worksheets("Sheet1").Columns(" J"), "2") Then

ErrorMSG = MsgBox("Warning.")

End If

Do i need to put this in the public sub function()...I am not too sure about
the full code .

thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default warning message

If you mean that you want to warn someone when they enter a value greater
than two into a cell in column J, then put this code into the worksheet's
code module (right-click sheet tab name and choose [View Code] from the list)

Private Sub Worksheet_Change(ByVal Target As Range)

If Application.Intersect(Target, Range("J:J")) Is Nothing Then
Exit Sub
End If
If Target.Cells.Count 1 Then
Exit Sub ' can't evaluate multiple cells
End If
If Target 2 Then
MsgBox "You have entered a value greater than 2.", vbOKOnly, "Value Error"
End If

End Sub

if you mean to warn them when they have made entries in more than two cells
in column J then this will work, goes into the worksheet code module also:

Private Sub Worksheet_Change(ByVal Target As Range)
Const colToTest = "J:J"
If Application.Intersect(Target, Range(colToTest)) Is Nothing Then
Exit Sub
End If
If Application.WorksheetFunction.CountA(ActiveSheet.R ange(colToTest)) 2 Then
MsgBox "You have entered values in more than two cells in column J.", _
vbOKOnly, "Data Entry Error"
End If

End Sub

"allan" wrote:

HI, I want to display a warning message in column J whenever the number
exceeds 2.

At the moment I got something like this....

Dim ErrorMSG As String

If Application.CountIf(Worksheets("Sheet1").Columns(" J"), "2") Then

ErrorMSG = MsgBox("Warning.")

End If

Do i need to put this in the public sub function()...I am not too sure about
the full code .

thanks

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 103
Default warning message

Allen
I try to keep it simple, is their no way you can just use Data Validation?
It has the error handler included. It will write the code for you.

Good Luck

--
William<"M"
Using 2007


"allan" wrote:

HI, I want to display a warning message in column J whenever the number
exceeds 2.

At the moment I got something like this....

Dim ErrorMSG As String

If Application.CountIf(Worksheets("Sheet1").Columns(" J"), "2") Then

ErrorMSG = MsgBox("Warning.")

End If

Do i need to put this in the public sub function()...I am not too sure about
the full code .

thanks

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning Message tom Excel Discussion (Misc queries) 4 December 13th 06 08:23 PM
Warning Message MLK Excel Worksheet Functions 2 June 29th 06 11:55 AM
warning message Mike Excel Discussion (Misc queries) 3 March 10th 06 06:20 PM
How to I get a warning message box shrek Excel Worksheet Functions 3 November 10th 05 12:23 AM
Warning message Paul Excel Discussion (Misc queries) 1 March 11th 05 11:07 PM


All times are GMT +1. The time now is 12:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"