View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1348_] Rick Rothstein \(MVP - VB\)[_1348_] is offline
external usenet poster
 
Posts: 1
Default Need help modifying VB script

It would be useful if you posted your actual code rather than an outline of
it (kind of hard to tell where your mistake is if we can't see your actual
code) and, if you are getting an error, telling us what error it is (kind of
hard to know what VB is complaining about if we can't see what it is
saying).

Rick


"DTLay" wrote in message
...
I am working on a script to change the background color of a cell when it
is
double-clicked. So far, I have this script, which works fine.....

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range,
Cancel
As Boolean)


If Target.Interior.ColorIndex = 50 Then

Target.Interior.ColorIndex = xlNone
Else

Target.Interior.ColorIndex = 50
End If



Cancel = True


End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

End Sub

I am trying to modify this so that the target color changes based on the
cell value. For instance, this is a grading sheet, and I'd like all
scores
of 1 or 2 to change to red, while 3 and 4 change to green. I've tried
using
an IF THEN statement around the above code to look at the value of the
cell
but it isn't working, likely because of the coding. I wrote:

IF Target.Value "2" Then...(original code)
Else...(Original code with different color value)

I am getting an error running this, and am hoping someone can tell me why.
I haven't programmed script in a long time, so I'm hoping it's a simple
fix.

Thanks!