VB Macro for digit

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello there,

Please help. I have coloured the cells in Rows A1:E1 blue.

Using a macro, I would like Excel to check each value in the above row and
colour the corresponding digit value blue in the range A5:E5.

(I have used up all 3 Conditional Format options, hence the need to use
macros for further cell formatting).

Thanx
 
Here is an example that changes the colour as the value is entered


'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "A5:E5" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case 1: .Offset(-1,0).Interior.ColorIndex = 3 'red
Case 2: .Offset(-1,0).Interior.ColorIndex = 6 'yellow
Case 3: .Offset(-1,0).Interior.ColorIndex = 5 'blue
Case 4: .Offset(-1,0).Interior.ColorIndex = 10 'green
Case 5: .Offset(-1,0).Interior.ColorIndex = 38
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top