Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting Color change in Excel cell

Status
Not open for further replies.

000Steve000

IS-IT--Management
Jul 9, 2004
50
0
0
GB
I would like to run a macro to check the contents of a cell when a user chages its colour. The colour change does not trigger the worksheet change event. Can anyone help?
 
I think your options are going to fall into two general categories:

1) Let your validation check be triggered by an unrelated event (maybe Selection_Change, or maybe just a timed check every 10 seconds, etc)

2) Design the spreadsheet in a way that forces the user to do something that triggers the change event for that cell.

Which approach would you be most interested in?

VBAjedi [swords]
 
The 2nd option sounds the most promising. Maybe removing built -in background colour toolbar function and replacing it with one of my own. I can't think what else you might have had in mind.
 
Hi,

Here's how it's done with with selecion change.

You store the ADDRESS of the PREVIOUS & CURRENT SELECTION and the corresponding PROPERTIES of those selections that you want to test in the SelectionChange event and then test the current state against the previous state. Keep in mind that multiple cells can be selected and changed.

Skip,
[sub]
[red]Be advised:[/red] [glasses]
Alcohol and Calculus do not mix!
If you drink, don't derive! [tongue][/sub]
 
Skip,

Thanks for you response, I understand the reasoning, but how can I pass the previous cell's location to the Selection Change when the Target parameter holds only the new location.
 
For the second option, what I had in mind was providing a button, floating toolbar button, or key combination that the user presses to flag/color a cell. All of these will allow you to easily append code that does your data check.

Another similar option would be to train them to right-click the cell they want to flag/highlight. Then use the BeforeRightclick event like this:
Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Excel.Range, Cancel As Boolean)
x = MsgBox("Flag/Color this cell?", vbYesNo)
If x = 6 Then ' user chose Yes
   ' Do your thing here
   Cancel = True ' Prevents right-click menu
Else
   ' Do nothing
End If
End Sub
Hope that helps!

VBAjedi [swords]
 
Thanks jedi (nice name!), but Skip's way allows the users to select the colours in the same way as they always have. I have now managed to keep track of the old cell location in the changeselection event using a public variable. I can then call the change event using the old location and check for the color change. Cheers guys.
 
You could, for instance, designate a sheet for these values. Make the sheet visible property xlsheetveryhidden. Name on cell Prev and another This

When you enter the selection change event, [Prev] = [This] and [This] = Target.Address

Skip,
[sub]
[red]Be advised:[/red] [glasses]
Alcohol and Calculus do not mix!
If you drink, don't derive! [tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top