vb routine that asks for user input and then highlight cells PLEASE HELP! :)

ausirepair

New Member
Joined
Nov 16, 2014
Messages
26
i need some help writing a routine called DryMonth() that will ask for user input and then highlight any cell that has a rainfall less than or equal to the input with a white font and a red background. TIA
33ttpvk.jpg
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
try this:

Code:
Option Explicit


Sub DryMonth()
    Dim lr As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    Dim c As Range
    Dim rng As Range
    Set rng = Range("B2:M" & lr)
    Dim qes As Double
    qes = InputBox("what is your target?")
    
    Application.ScreenUpdating = False
    For Each c In rng
    If c.Value <= qes Then
    c.Font.ColorIndex = 2
    c.Interior.ColorIndex = 3
    End If
    Next c
    Application.ScreenUpdating = True
    MsgBox "complete"
        
End Sub
 
Upvote 0
You could do this by creating a Named Value HighlightLimit
and put Conditional Formatting formula =(A1 < HighlightLimit) on all the cells.

Then this code could change the value of HighlightLimit depedng on the user's entry.

Code:
Sub Test()
    Dim uiValue as Double
    
    uiValue = Application.InputBox("Enter Hightlighting Limit", type:=1)
    If uiValue <=0 Then Exit Sub: Rem user canceled

    ThisWorkbook.Names.Add Name:="HighlightLimit", RefersTo:= "=" & uiValue
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

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