Re: VBA
- From: "Don Guillett" <dguillett1@xxxxxxxxxxxxx>
- Date: Sun, 22 Feb 2009 07:27:49 -0600
Show your FINAL code. A worksheet change event works on changing the cell so it should be UN protected.
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@xxxxxxxxxxxxx
"FP Novice" <FPNovice@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:66AFAB7B-0B77-4F39-BEC4-8A7D22460A8B@xxxxxxxxxxxxxxxx
Perfect Don, much cleaner than what I had. I did leave the opening string:
Private Sub Worksheet_Change(ByVal Target As Range)
The rest I converted to what you gave me, thanks.
I do have another question, how can I make the macro work when G6, J6, and
K6 are protected cells, since they hold functions I want protected.
Thanks again,
Todd
"Don Guillett" wrote:
Try it this way
Sub Colorif()
Dim c
For Each c In Array("g6", "j6", "k6")
Dim Num As Long
Dim rng As Range
Set rng = Range(c)
' Application.EnableEvents = False
'Determine the color
Select Case UCase(rng.Value)
Case Is = "BLUE": Num = 5 'blue
Case Is = "ORANGE": Num = 45 'orange
Case Is = "GREEN": Num = 10 'green
Case Is = "BROWN": Num = 53 'brown
Case Is = "SLATE": Num = 15 'slate
Case Is = "WHITE": Num = 2 'black
Case Is = "RED": Num = 3 'red
Case Is = "BLACK": Num = 1 'black
Case Is = "YELLOW": Num = 6 'yellow
Case Is = "VIOLET": Num = 54 'violet
Case Is = "ROSE": Num = 38 'rose
Case Is = "AQUA": Num = 42 'aqua
Case Else
Num = 0
End Select
'Apply the color
rng.Font.ColorIndex = Num
'Application.EnableEvents = True
Next c
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@xxxxxxxxxxxxx
"FP Novice" <FPNovice@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:441617BA-1AD4-48B2-8201-049E51438E60@xxxxxxxxxxxxxxxx
>I have these macro's built to run on my (Lookup) Sheet1. My trouble is >that
> they work fine when I play each individual macro; however, I cannot get
> them
> to run automatically. My security is set to low and I have 'Trust all
> installed add-ins and templates' checked.
>
> MS Excel 2003
>
> Thanks,
> Todd
>
>
>
> Sub Color_G6()
> Dim Num As Long
> Dim rng As Range
> Set rng = Me.Range("G6")
> On Error GoTo endit
> Application.EnableEvents = False
> 'Determine the color
> Select Case UCase(rng.Value)
> Case Is = "BLUE": Num = 5 'blue
> Case Is = "ORANGE": Num = 45 'orange
> Case Is = "GREEN": Num = 10 'green
> Case Is = "BROWN": Num = 53 'brown
> Case Is = "SLATE": Num = 15 'slate
> Case Is = "WHITE": Num = 2 'black
> Case Is = "RED": Num = 3 'red
> Case Is = "BLACK": Num = 1 'black
> Case Is = "YELLOW": Num = 6 'yellow
> Case Is = "VIOLET": Num = 54 'violet
> Case Is = "ROSE": Num = 38 'rose
> Case Is = "AQUA": Num = 42 'aqua
> End Select
> 'Apply the color
> rng.Font.ColorIndex = Num
> endit:
> Application.EnableEvents = True
> End Sub
>
> Sub Color_J6()
> Dim Num As Long
> Dim rng As Range
> Set rng = Me.Range("J6")
> On Error GoTo endit
> Application.EnableEvents = False
> 'Determine the color
> Select Case UCase(rng.Value)
> Case Is = "BLUE": Num = 5 'blue
> Case Is = "ORANGE": Num = 45 'orange
> Case Is = "GREEN": Num = 10 'green
> Case Is = "BROWN": Num = 53 'brown
> Case Is = "SLATE": Num = 15 'slate
> Case Is = "WHITE": Num = 2 'black
> Case Is = "RED": Num = 3 'red
> Case Is = "BLACK": Num = 1 'black
> Case Is = "YELLOW": Num = 6 'yellow
> Case Is = "VIOLET": Num = 54 'violet
> Case Is = "ROSE": Num = 38 'rose
> Case Is = "AQUA": Num = 42 'aqua
> End Select
> 'Apply the color
> rng.Font.ColorIndex = Num
> endit:
> Application.EnableEvents = True
> End Sub
>
> Sub Color_K6()
> Dim Num As Long
> Dim rng As Range
> Set rng = Me.Range("K6")
> On Error GoTo endit
> Application.EnableEvents = False
> 'Determine the color
> Select Case UCase(rng.Value)
> Case Is = "BLUE": Num = 5 'blue
> Case Is = "ORANGE": Num = 45 'orange
> Case Is = "GREEN": Num = 10 'green
> Case Is = "BROWN": Num = 53 'brown
> Case Is = "SLATE": Num = 15 'slate
> Case Is = "WHITE": Num = 2 'black
> Case Is = "RED": Num = 3 'red
> Case Is = "BLACK": Num = 1 'black
> Case Is = "YELLOW": Num = 6 'yellow
> Case Is = "VIOLET": Num = 54 'violet
> Case Is = "ROSE": Num = 38 'rose
> Case Is = "AQUA": Num = 42 'aqua
> End Select
> 'Apply the color
> rng.Font.ColorIndex = Num
> endit:
> Application.EnableEvents = True
> End Sub
>
>
.
- Prev by Date: Re: Form Toolbox pops up?
- Next by Date: double a 5 by 5 cell table
- Previous by thread: Re: VBA
- Next by thread: Clearing Comments
- Index(es):
Relevant Pages
|