Simple VBA code question

percy83

Active Member
Joined
Mar 11, 2009
Messages
278
Hi all,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
I’ve got the following code in my workbook. The cells in rng1 below contains a formula that will display “days until deadline” figure. Problem is that I need to refresh the whole sheet for the color to change even though the figure in the cell changes from one case to another. <o:p></o:p>
<o:p> </o:p>
Please enlighten me.<o:p></o:p>
<o:p> </o:p>
<o:p>Thanks! </o:p>
Best regards<o:p></o:p>
Per<o:p></o:p>
<o:p> </o:p>
Code:
Private Sub Worksheet_Change(ByVal Target As Range)<o:p></o:p>
Dim Cell As Range<o:p></o:p>
Dim Rng1 As Range<o:p></o:p>
Set Rng1 = Intersect(Range("J2:J300,O2:O300"), Target)<o:p></o:p>
If Not Rng1 Is Nothing Then<o:p></o:p>
    For Each Cell In Rng1<o:p></o:p>
        Select Case Cell.Value<o:p></o:p>
        Case vbNullString<o:p></o:p>
                Cell.Interior.ColorIndex = xlNone<o:p></o:p>
                Cell.Font.Bold = False<o:p></o:p>
                Cell.Font.ColorIndex = 1<o:p></o:p>
                Cell.Font.Name = "arial"<o:p></o:p>
                <o:p></o:p>
            Case -3000 To 0<o:p></o:p>
                Cell.Interior.ColorIndex = 3<o:p></o:p>
                Cell.Font.Name = "arial narrow"<o:p></o:p>
                Cell.Font.Bold = True<o:p></o:p>
                Cell.Font.ColorIndex = 2<o:p></o:p>
                <o:p></o:p>
                Case 1 To 14<o:p></o:p>
                Cell.Interior.ColorIndex = 6<o:p></o:p>
                Cell.Font.Name = "arial narrow"<o:p></o:p>
                Cell.Font.Bold = True<o:p></o:p>
                Cell.Font.ColorIndex = 1<o:p></o:p>
            <o:p></o:p>
            Case 15 To 1000<o:p></o:p>
                Cell.Interior.ColorIndex = 10<o:p></o:p>
                Cell.Font.Name = "arial narrow"<o:p></o:p>
                Cell.Font.Bold = True<o:p></o:p>
                Cell.Font.ColorIndex = 2<o:p></o:p>
                <o:p></o:p>
            Case Else<o:p></o:p>
                Cell.Interior.ColorIndex = xlNone<o:p></o:p>
                Cell.Font.Bold = False<o:p></o:p>
                Cell.Font.Name = "arial narrow"<o:p></o:p>
                Cell.Font.ColorIndex = 1<o:p></o:p>
        End Select<o:p></o:p>
    Next<o:p></o:p>
 End If<o:p></o:p>
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
The Worksheet_Change event fires when a cell is changed by the user. It does not fire when the value in a cell that contains a formula changes. So Target can never be one of your formula cells. The Worksheet_Calculate event fires when the value in a cell that contains a formula changes.
 
Upvote 0
OK so how do I apply this to my vba code? I can't just change from worksheet_change to worksheet_calculate that doesent work.

Pls help me?

Thanks in advance!
P
 
Upvote 0
You can't just replace Change with Calculate because the Worksheet_Calculate event procedure doesn't have a Target argument. To get a correctly constructed procedure stub, in the VBE module window select Worksheet from the left hand drop down and Calculate from the right hand dropdown.
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,178
Latest member
Emilou

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