Failing to use VBA to change color when conditions are met

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
303
Office Version
  1. 365
I've looked at several similar examples of the issue I'm having, but I'm still missing something.


I want to change the color of a frame to red when a cell value is NOT "on hold" and when another cell value is either NOT "ND" or NOT over 100%. Otherwise, I want the frame to stay the original color (the RGB definition).


Code:
        If Worksheets("Details").Range("D16") <> "On Hold" Then
            If Worksheets("Details").Range("O13") = "ND" Or Worksheets("Details").Range("O13") > 0.1 Then
                Me.DaysFrame.BorderColor = vbRed
            Else
                Me.DaysFrame.BorderColor = RGB(128, 128, 128)
            End If
        End If

I've tried variations like this portion of code:


Code:
If Worksheets("Details").Range("D16") <> "On Hold" And (Worksheets("Details").Range("O13") = "ND" Or Or Worksheets("Details").Range("O13") > 0.1) Then...
But the solution continues elude me.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I should have said that the result of the code I provided above always gives me a red border despite the conditions.
 
Upvote 0
I've looked at several similar examples of the issue I'm having, but I'm still missing something.


I want to change the color of a frame to red when a cell value is NOT "on hold" and when another cell value is either NOT "ND" or NOT over 100%. Otherwise, I want the frame to stay the original color (the RGB definition).


Code:
        If Worksheets("Details").Range("D16") <> "On Hold" Then
            [B][COLOR="#FF0000"]If Worksheets("Details").Range("O13") = "ND" Or Worksheets("Details").Range("O13") > 0.1 Then[/COLOR][/B]
                Me.DaysFrame.BorderColor = vbRed
            Else
                Me.DaysFrame.BorderColor = RGB(128, 128, 128)
            End If
        End If
(Untested) Based on your written description, I would think your second If..Then statement should be this...
Code:
[table="width: 500"]
[tr]
	[td]If Worksheets("Details").Range("O13") <> "ND" Or Worksheets("Details").Range("O13") < 1 Then[/td]
[/tr]
[/table]
 
Upvote 0
Thanks, Rick. I did a poor job of writing that. I should have said if that range is equal to ND or the other range is greater than 100%.
 
Upvote 0
My logic seemed correct, so that left my calculations and that's where I found the problem. I was testing against the wrong figure. Frustrating, but at least the issue is solved.


Thanks again, Rick, for your help though.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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