473,387 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Excel: Trigger Event when Cell Value Changes due to Calculation

I have a spreadsheet (Excel 2003*)

Column C changes to "Y" when all the necessary data has been input in that row. I want a message box to appear when the value in column C changes to Y for the active row.

I am using this code but it fires every time any cell chnges.
Expand|Select|Wrap|Line Numbers
  1. Dim rngC As Range
  2. Set rngC = Intersect(Range("C201:C64000"), Target)
  3. If rngC.Value = "Y" Then
  4. MsgBox "Data Complete"
  5. End If
  6.  
What can I do?

Thanks in advance

phil

*Sorry they only gave me 2003
Mar 30 '12 #1
13 15361
NeoPa
32,556 Expert Mod 16PB
Please include the procedure declaration line as without it, and without any explanation in your question, we have no idea how this code is triggered. It seems contradictory, but its hard to tell with most of the important information missing.
Phil:
*Sorry they only gave me 2003
What on Earth would you want another version for? 2003 is the most solid and reliable version released for a good long time. 2010 may attain that reputation eventually, but it'll have a way to go to reach the status 2003 has earned.
Mar 30 '12 #2
Sorry, I have put the code in worksheet on calculate.
Mar 31 '12 #3
Mihail
759 512MB
Column "C" can't change to "Y".
I assume that a cell in column "C" is changed to "Y".
If so, this code will "see" if that cell contain "Y".
Put it in the sheet module.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim TargetRow As Long
  3.  
  4. Private Sub Worksheet_Change(ByVal Target As Range)
  5.     'If a change appear in other column than "C" nothing to do
  6.     If Target.Column <> 3 Then
  7. Exit Sub
  8.     End If
  9.     'If a change appear in other row than TargetRow nothing to do
  10.     If Target.Row <> TargetRow Then
  11. Exit Sub
  12.     End If
  13.     If Target.Value = "Y" Then
  14.         'Do something
  15.     End If
  16. End Sub
Mar 31 '12 #4
NeoPa
32,556 Expert Mod 16PB
Phil:
Sorry, I have put the code in worksheet on calculate.
That is not an explanation, and it still doesn't include the code with the information in it. I suspect the event you're using is inappropriate, but I don't plan to check out all the details for you when you don't even post what you have.

I suspect Mihail's code uses the event you want, but be careful of assuming only one cell is ever updated at a time. Target can often refer to a range, or even multiple ranges, of contiguous cells.
Apr 1 '12 #5
The code is at work. I will post it Monday.
Apr 1 '12 #6
NeoPa
32,556 Expert Mod 16PB
Ah. Makes sense that you didn't post the details then :-D

Never mind. Target isn't a parameter for Worksheet_Calculate(), as it happens, so your code won't make sense anyway. I suggest you follow Mihail's lead and use Worksheet_Change(ByVal Target As Range) instead.

Target.Address() will return the full list of ranges effected by the change. Alternatively, using something like the following allows you to process through all included cells :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     Dim ranVar As Range
  3.  
  4.     For Each ranVar in Target
  5.         With ranVar
  6.             If .Column = 3 And .Value = "Y"  Then _
  7.                 MsgBox "Data complete for row " & .Row
  8.         End With
  9.     Next ranVar
  10. End Sub
Apr 1 '12 #7
Guys, these only work if I go into the cell and change the value manually. But the cell is a result of a calculation that changes to "Y" when the correct cells have been filled. (Cells needing completion and info needed depend upon type of record.)
So I need to monitor the cell and get a pop up message when the result of the calcualtion changes.
This is the original code I put in
Expand|Select|Wrap|Line Numbers
  1. Private Sub Worksheet_Calculate()
  2.  
  3. Dim rngC As Range
  4. Set rngC = Intersect(Range("C201:C64000"), Target)
  5. On Error Resume Next
  6.  
  7.  
  8. If rngC.Value = "Y" Then
  9. MsgBox "Data Complete"
  10. End If
  11.  
  12.  
  13. Hide: 'Filter button
  14. If ActiveSheet.FilterMode = True Then
  15. ActiveSheet.Shapes("Rectangle 183").Visible = True
  16. Else
  17. ActiveSheet.Shapes("Rectangle 183").Visible = False
  18. End If
  19. End Sub
The bit at the bottom hides/shows a button, but shouldn't make any difference, thought I'd best include it for completeness.
Apr 2 '12 #8
Figured it out thanks guys. I just had to think a bit harder and you pushed me in the right direction. This is what I ended up doing.

I made a formula on the sheet that was the sum of column C, counting a "Y" as 1. If that value increased, soomething must have changed to "Y" so:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  'Monitor C198 sum of completed records
  3. Dim Monitored
  4.  
  5. Private Sub Worksheet_Activate()
  6. 'remember C198
  7. Monitored = Range("c198").Value 
  8.  
  9. End Sub
  10.  
  11. Private Sub Worksheet_Change(ByVal Target As Range)
  12. If Range("C198").Value = Monitored + 1 Then
  13. MsgBox "Data Complete for serial " & Target.Row - 200
  14. 'reset   
  15. Monitored = Range("C198").Value
  16. End If
  17.  
  18. If Range("C198").Value <> Monitored + 1 Then
  19. 'reset
  20. Monitored = Range("C198").Value
  21. End If
Apr 2 '12 #9
Mihail
759 512MB
Good for you, even if I can't understand your logic.
Are you sure that monitorized cell, will be, from now forever, the cell C198 ?
Or, if you will add tomorrow only one row, you'll need to change the code ?
Apr 2 '12 #10
@Mihail
Rows 1 to 197 are hidden, they have autocomplete lists above the data. Rows 197 to 200 are Titles. All data is row 201 onwards. The users have an action button to insert new rows at the end.
The workbook is VERY locked down. Each row starts with 1 cell that the users enter data into, depending what they enter other cells unlock in that row until they have entered all the necessary data.
As for understanding my logic I have problems with that as well :>)

Thanks for your help Mihail
Apr 2 '12 #11
NeoPa
32,556 Expert Mod 16PB
Phil:
Guys, these only work if I go into the cell and change the value manually. But the cell is a result of a calculation that changes to "Y" when the correct cells have been filled. (Cells needing completion and info needed depend upon type of record.)
You're quite right of course. I noticed that when I first looked at the question, but when I revisited it I overlooked that point.

Your solution is workable, but as I'm sure you appreciate, somewhat clumsy. That is the nature of the situation though, rather than a dig at your coding abilities. If I were trying to do exactly that, I would come up with a similarly clumsy solution.

An alternative might be to take a step back at this point then, and look at your actual, overall, requirement. Is it necessary for column C to contain a formula at all if you are already needing to use code to handle the situation. Why not use the Worksheet_Change() event procedure to determine the status (Value in column C) itself, in which case it knows exactly when the status changes? Just a different way of looking at it.
Apr 2 '12 #12
There are 42 different types of record and hence 42 different ways of getting "Y" for record complete. Getting the "Y" in column C takes calculations in 8 other columns ensuring that all the correct fields have been completed. I suppose I could have nested them in 2 or three cells, but that would have been really confusing if anything needed to change. Getting that done in VB is well beyond me. Clumsy but workable will have to do.

Thanks Neo

Also it should have been done in Access, but they want Excel.
Apr 2 '12 #13
NeoPa
32,556 Expert Mod 16PB
It was just an idea.

It's quite right that you determine what suits you best once the ideas are on the table.
Apr 2 '12 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: codecraig | last post by:
Hi, I am using Tkinter and I have a Label and a Scale. I want to update my label everytime the Scale value changes. What is the best way of doing this? Do i have to bind for every event type? ...
4
by: Rodger Dusatko | last post by:
In VB .NET I am having problems setting breaks. I want the break to be independant of any single function: for example: err.number or global variables When I try to set a break with the 'Data'...
3
by: Dustin Davis | last post by:
Is it possible to trigger an event in VB.NET whenever anything is copied to the clipboard?
7
by: Macolm64 | last post by:
I am looking for some code that would loop until two cell values in excel equal the same. By cell value I mean the result of the formulas in the cells are the same. This procedure needs to be run...
2
by: Tom_F | last post by:
To comp.databases.ms-access -- I would like to trigger an event when I close a form -- but ONLY when the data in the "RecordSource" table has been updated. I tried using the AfterUpdate event,...
2
by: kilik3000 | last post by:
Is there a way to catch an event/trigger that *might* be fired when a usb thumb drive is inserted into a Vista PC? The reason I ask is that I'd like to catch that event and back up the content...
1
bergy
by: bergy | last post by:
I have a user control class, when a user selects the control (or it's children) the background of the control turns blue. When the user exits, it returns to its "unselected" state. I have...
3
by: crjunk | last post by:
Hi Everyone, I have a web form that I would like to enhance. What I'd like to do is this: A user adds/edits the text in a textbox. I want the adjoining label to change color. Example: User...
5
by: dave816 | last post by:
Sorry for the Excel question in an Access forum...................I don't see an Excel forum and there's probably a reason for that but figured I'd give this a shot anyway. Again sorry, delete if...
2
by: Dresse | last post by:
Hello I was wondering if it is possible to define a save location when a value in a combobox is selected. ex. Combobox: a b c
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.