Do you know Excel VBA script?

bovinda

Senior member
Nov 26, 2004
692
0
0
I have a code I can't get to work in Excel 2007 on a spreadsheet that I updated.

It's a simple script to change font color in one cell, if an adjacent cell has pre-specified data (some combination of words).

But I can't get it to run. So I'm trying to understand what the commands mean, in simple language.

EDIT 6/13: It's working now, thanks guys!

 

mayest

Senior member
Jun 30, 2006
306
0
0
Well, you should probably be using Conditional Formatting rather than VBA for this. With that said, "Select Case" is a VBA statement that basically says "if the value equals one of these listed values then do the appropriate action." So, it will have two or more possibilities and will choose one based on the value of some variable.

Target.Offset selects a cell that is a certain number of rows and/or columns away from the "target" cell.
 

bovinda

Senior member
Nov 26, 2004
692
0
0
Thanks for the clarification...OK, it makes more sense then...those aren't the problem. The code is now saying that my use of the "Me" statement is invalid in these lines when I try to compile it:

Me.Cells(Target.Row, "B").Font.ColorIndex = myColor

Any idea what that means?

The reason I don't use conditional formatting for this is because it would require well more than three possible conditions (the data the font color is dependent on are a selection of more than 15 words, not numerical).
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
Where is this code located? If it is in the workbook it will work. If it is in a module then it will not.
 

bovinda

Senior member
Nov 26, 2004
692
0
0
Oooohhhh...maybe that would explain! Ok, stupid question then...how do I put it into a workbook instead of a module? What did I miss? I can't seem to figure out how to get the code into the right place.
 

bovinda

Senior member
Nov 26, 2004
692
0
0
OK, I think I figured out where to put it...I R-clicked on the worksheet tab, clicked "View Code", and put it there. But my code still isn't working. No errors, it just doesn't work. :(


Edit: the problem was macros weren't enabled. It's working now! Thanks you guys.