I hate to step on someone's toes, but I think I need to here. If you use a VBA solution, you should put it in the Change event (as opposed to the SelectionChange event), something like this:<pre><font color='#000000'><font color='#000080'>Option</font><font color='#000080'>Explicit</font><hr align=left width=500><font color='#000080'>Private</font><font color='#000080'>Sub</font> Worksheet_Change(ByVal Target<font color='#000080'>As</font> Range)<font color='#000080'>Dim</font> cl<font color='#000080'>As</font> Range<font color='#000080'>Dim</font> rngIntersect<font color='#000080'>As</font> Range<font color='#008000'>' Put the range of cells that you want to evaluate where</font><font color='#008000'>' I have Range("D:D"). So in this example, if a number in</font><font color='#008000'>' column D has a number greater than 1, then the cell in the</font><font color='#008000'>' same row in column E gets a Percentage format,</font><font color='#008000'>' otherwise it gets a General format.</font><font color='#008000'>' (Offset(0,1) gives the cell to the right of the current</font><font color='#008000'>' cl - for more info, look Offset up in VBA help).</font><font color='#008000'>' You can change this to make it change the cell(s) of your</font><font color='#008000'>' choice...</font><font color='#000080'>Set</font> rngIntersect = Intersect(Range("D:D"), Target)<font color='#000080'>If</font><font color='#000080'>Not</font> rngIntersect Is Nothing<font color='#000080'>Then</font><font color='#000080'>For</font><font color='#000080'>Each</font> cl In rngIntersect<font color='#000080'>If</font> cl.Value > 1<font color='#000080'>Then</font>
cl.Offset(0, 1).NumberFormat = "0.00%"<font color='#000080'>Else</font>
cl.Offset(0, 1).NumberFormat = "General"<font color='#000080'>End</font><font color='#000080'>If</font><font color='#000080'>Next</font> cl<font color='#000080'>End</font><font color='#000080'>If</font><font color='#000080'>End</font><font color='#000080'>Sub</font></font></pre>
-
If you use the selection change event, then your event will fire (and check all cells with text in column D) every time you move from cell to cell. You would most likely only want the formats to change if one of the dependant cells changes.
Also, the code above needs to go into the Worksheet module. To learn a little bit about workbook/worksheet modules, click
HERE
HTH,
Russell
This message was edited by Russell Hauf on 2002-11-14 18:43