Help: Auto colour cell based on input in another cell

Sha

New Member
Joined
Oct 6, 2021
Messages
30
Office Version
  1. 2013
Platform
  1. Windows
Hi out there,

i am trying to get the col J (date) to change colour after a certain number of days if cell F (date) is empty. Below are my codes. Could anyone tell me what i am doing wrong. Please do bare with me as i am really new at VBA.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   If Target.Cells.Value > 0 Then Exit Sub

   Set xRg = Intersect(Range("F1:F3000"), Target)

   If xRg Is Nothing Then Exit Sub

   If IsNumeric(Target.Value) And Target.Value = "" Then

   Call HighlightCells


    End If

End Sub

 


Sub HighlightCells()


Dim dtrg As Range: Set dtrg = Range("J1:J3000")

Dim dtCell As Range

For Each dtCell In dtrg.Cells

If dtCell.Value <> "" And dtCell.Value < Date - 40 Then _

    dtCell.Interior.ColorIndex = 3


'End If

Next dtCell
 
Hi Dan,

Yes that is correct. the range kept reading F3 and J3 rather than F2 and J2 which is the start of data. Could i also ask a question?

When implementing a Conditional formatting...it only applies to the active sheet right? is there any way that I could apply the condition once to the whole workbook, so that there is no need to repeat the process of implementing of CF for each worksheet?
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I'm so sorry - This completely escaped my attention.
Unfortunately, conditional formatting will only apply to one worksheet. If you wanted to automatically replicate the CF across the entire workbook, you would need to use VBA. I don't think it would require much knowledge, though, to be honest. Have you ever used the Macro Recorder before? Basically, what it does is it watches what you do, and then generates VBA code for you, that you can assign to a button and then click to reproduce the same results on each worksheet. With a tiny bit of VBA, you could ever skip having to press the button for each worksheet! Is that something you'd like to try?
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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