Conditional Formatting based on another cells

sg2209

Board Regular
Joined
Oct 27, 2017
Messages
117
Office Version
  1. 2016
hi Friends ,

Regarding conditional formatting i have checked couple of examples and created the below code however its not working not sure why , Could anyone please review and share where i am making a mistake , also if need to apply this only in the specific sheet names Raw , how do i append it .

Dim k As Long, r1 As Range, r2 As Range
For k = 2 To 5
Set r1 = Range("C18" & k)
Set r2 = Range("B29" & k & ":C33" & k)
If r1.Value >= 500 Then r2.Interior.Color = vbGreen
If r1.Value > 1000 Then r2.Interior.Color = vbYellow
If r1.Value > 2000 Then r2.Interior.Color = vbRed
If r1.Value > 5000 Then r2.Interior.Color = vbYellow
If r1.Value >= 5000 Then r2.Interior.Color = vbYellow






Next k
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You could use actual Conditional Formatting instead of vba code.

First select cells B29:C33 and enter these CF forualas in this order...

Condition 1
Formula is: =$C18>=5000 'Background color Yellow

Condition 2
Formula is: =$C18>=2000 'Background color Red

Condition 3
Formula is: =$C18>=1000 'Background color Yellow

Condition 4
Formula is: =$C18>=500 'Background color Green


Excel will automatically change the formula cell reference $C18 for each row.
 
Upvote 0
Thank you So much however i am using this in a Form which is getting prepared through VBA , so i need to use this in that .
 
Upvote 0
You could have VBA set the actual Conditional Formatting formulas.

Your code is ambiguous. Can you better explain the criteria, conditions and data ranges?
 
Upvote 0
below is the condition when i used in Excel , however i am not able to convert this in VBA even i did try it with teh above Code

=And($C18>=1,$C18<=500) then Cell B29:C33 Should be Yellow
=And($C18>=501,$C18<=1000) then Cell B29:C33 Should be Yellow
=And($C18>=1001,$C18<=2000) then Cell B29:C33 Should be Yellow
=And($C18>=2001,$C18<=5000) then Cell B29:C33 Should be Yellow
=And($C18>5000) then Cell B29:C33 Should be Yellow
 
Upvote 0
i have tried with below code its not working too , keeps on Highlighting B29
If Range("C18") <= "500" Then
Range("B29:C29").Interior.Color = vbYellow
End If


With Sheets("INS REFUND CHECK REQ").Range("B29:C33").Select
Range("B29:C33").Interior.Pattern = xlNone
End With


If Range("C18") < "501" And Range("C18") >= "1000" Then
Range("B30:C30").Interior.Color = vbGreen
End If




With Sheets("INS REFUND CHECK REQ").Range("B29:C33").Select
Range("B29:C33").Interior.Pattern = xlNone
End With


If Range("C18") >= "1001" And Range("C18") <= "2000" Then
Range("B31:C31").Interior.Color = vbYellow
End If


With Sheets("INS REFUND CHECK REQ").Range("B29:C33").Select
Range("B29:C33").Interior.Pattern = xlNone
End With


If Range("C18") >= "2001" And Range("C18") <= "5000" Then
Range("B32:C32").Interior.Color = vbYellow
End If




With Sheets("INS REFUND CHECK REQ").Range("B29:C33").Select
Range("B29:C33").Interior.Pattern = xlNone
End With
If Range("C18") > "5000" Then
Range("B33:C33").Interior.Color = vbYellow
End If
 
Last edited:
Upvote 0
Hi All ,

the above code works well when i add $C18,

thank you all for the efforts
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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