Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default I want a msgbox when the contents of cell change

Hi
use the following worksheet event code. Put this in your worksheet
module:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("C13:C15")) Is Nothing Then
Exit Sub
End If
with target
if .value = "AL" or .value="HDAY" then
msgbox "You entered: " & .value
end if
end with

End Sub

--
Regards
Frank Kabel
Frankfurt, Germany


Matt wrote:
I have a range of cells(C13:C15) that the user inputs data. There
are actually more cells that I want to check, but this is a sample.
What I want is for Excel to check the cell after the user inputs data
to see if they put in "AL" or "HDAY". If they put in "AL", then I
want a messagebox to come up saying that they entered "AL" and the
same for if they enter "HDAY". If they enter anything else in the
cell, I don't want it to do anything. I want this code to run
everytime a user inputs data in this range of cells. Thanks in
advance. Matt


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default I want a msgbox when the contents of cell change

Matt

Here's a non-macro solution in case you're interested. Select Validation
from the Data menu, Custom from the dropdown and put this in the formula box
(assuming you're in A1 when you do it)

=AND(A1<"HDAY",A1<"AL")

Then on the Error Alert Tab, change to Information and type in your message.
You can copy this validation to whatever cells you like. You don't get a
custom message - it would be the same for either value entered.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

Frank Kabel wrote:
Hi
use the following worksheet event code. Put this in your worksheet
module:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("C13:C15")) Is Nothing Then
Exit Sub
End If
with target
if .value = "AL" or .value="HDAY" then
msgbox "You entered: " & .value
end if
end with

End Sub


Matt wrote:
I have a range of cells(C13:C15) that the user inputs data. There
are actually more cells that I want to check, but this is a sample.
What I want is for Excel to check the cell after the user inputs data
to see if they put in "AL" or "HDAY". If they put in "AL", then I
want a messagebox to come up saying that they entered "AL" and the
same for if they enter "HDAY". If they enter anything else in the
cell, I don't want it to do anything. I want this code to run
everytime a user inputs data in this range of cells. Thanks in
advance. Matt



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 516
Default I want a msgbox when the contents of cell change

Thanks Frank. I have a couple of questions. First, what do I do if I already have code in the worksheet_change sub that references a different range a target? Will this cause a problem to have two different ranges referenced as target in the same sub? Also, when I stated that I wanted it to display a message box the actual message was different for each option(AL,HDAY). So I can't use this line of code.
if .value = "AL" or .value="HDAY" then
msgbox "You entered: " & .value
What I need is an if statement that checks for one or the other. My problem is when I split this up into an if and elseif, no matter which one the user enters, I always get the results of the if. Any suggestions. Thanks. Matt


"Frank Kabel" wrote:

Hi
use the following worksheet event code. Put this in your worksheet
module:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("C13:C15")) Is Nothing Then
Exit Sub
End If
with target
if .value = "AL" or .value="HDAY" then
msgbox "You entered: " & .value
end if
end with

End Sub

--
Regards
Frank Kabel
Frankfurt, Germany


Matt wrote:
I have a range of cells(C13:C15) that the user inputs data. There
are actually more cells that I want to check, but this is a sample.
What I want is for Excel to check the cell after the user inputs data
to see if they put in "AL" or "HDAY". If they put in "AL", then I
want a messagebox to come up saying that they entered "AL" and the
same for if they enter "HDAY". If they enter anything else in the
cell, I don't want it to do anything. I want this code to run
everytime a user inputs data in this range of cells. Thanks in
advance. Matt



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
change cell contents when pull down menu choices change jb21 Excel Worksheet Functions 3 November 21st 08 10:34 PM
Insert new row as cell contents change George Excel Discussion (Misc queries) 2 January 26th 05 11:47 AM
MsgBox for a range and not one cell change please: ste mac Excel Programming 6 May 22nd 04 07:18 PM
Please help! Macro to change cell contents based on cell to the left Jennifer[_8_] Excel Programming 7 March 4th 04 01:06 AM
Run macro when cell contents change Bob Phillips[_5_] Excel Programming 0 September 27th 03 12:28 PM


All times are GMT +1. The time now is 05:59 PM.

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"