VB question

cornishteeth

Board Regular
Joined
Dec 6, 2002
Messages
117
I am new to visual basic and am trying to learn. Basic question....I understand how excel uses conditional formatting to change the colors/fonts/etc. based on a inputted parameter. What I don't understand is how it is written in VB. Is there a way in Excel to display what actually is written in VB when say a text box changes color from red to blue because the total went below 100? Any help would be appreciated and any code fragments also help me understand.

Thanks,

Cornishteeth
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hullo. This should start you along what you need:
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range) 'name of the subroutine
Dim rngPriority
Dim rngCellPriority
Dim strColour  'set some variables
Application.ScreenUpdating = False  'keeps the screen from going beserk
With Worksheets("Sheet1")
    Set rngPriority = .Range(.Range("C1"), .Range("C65535").End(xlUp))
End With  'selects the range to use

For Each rngCellPriority In rngPriority  'loops through the ranges
    strColour = LCase(rngCellPriority.Value)
    Select Case strColour
        Case "very low"
            rngCellPriority.Interior.Color = vbGreen
        Case "low"
            rngCellPriority.Interior.Color = vbYellow
        Case "moderate"
            rngCellPriority.Interior.Color = vbMagenta
                'VB has no simple name for orange. Go figure
        Case "high"
            rngCellPriority.Interior.Color = vbRed
        Case Else
    End Select
Next rngCellPriority
Application.ScreenUpdating = True 'turn screen updating back on
End Sub

HTH

P
 
Upvote 0
cornishteeth said:
...What I don't understand is how it is written in VB. Is there a way in Excel to display what actually is written in VB when say a text box changes color from red to blue because the total went below 100?...

Are you asking what's the code that Excel uses to work with Conditional Formatting ? or are you asking how do you set up Conditional Formatting through VBA ? or what ?
 
Upvote 0

Forum statistics

Threads
1,221,695
Messages
6,161,360
Members
451,699
Latest member
sfairbro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top