Highlight cells using VBA

Paul365

New Member
Joined
Oct 29, 2021
Messages
21
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
Hello,

I was wondering if there is a possibility that VBA can be used to highlight cells, if a cell figure matches another. or a conditional formatting formula

Example (Using Time)
A2 - A 70 is marked (A2)7:00am, (A3)7:15 am, (A4)7:30 am etc.
If I insert a time in a different sheet (lets say sheet 2)- I would like the same cells to highlight in-between times.
Example
Cell A2 on sheet 2 - I type (Start time)8:00 am - and B1 I type (Finish Time)4:00 pm
I would Like Sheet 1 to highlight a color from A6 to A38 automatically
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try:
On Sheet2:
Dante Amor
AB
1Start TimeFinish Time
208:0016:00
Sheet2


Cell A2 must have the range name "s_time" and cell B2 must have the range name "f_time"

1669328743440.png


1669328908169.png


Conditional format on Sheet1:
Dante Amor
A
207:00
307:15
407:30
507:45
608:00
708:15
808:30
908:45
1009:00
1109:15
1209:30
1309:45
1410:00
1510:15
1610:30
1710:45
1811:00
1911:15
2011:30
2111:45
2212:00
2312:15
2412:30
2512:45
2613:00
2713:15
2813:30
2913:45
3014:00
3114:15
3214:30
3314:45
3415:00
3515:15
3615:30
3715:45
3816:00
3916:15
4016:30
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:A156Expression=AND($A2>=s_time,$A2<=f_time)textNO
 

Attachments

  • 1669328756656.png
    1669328756656.png
    5.6 KB · Views: 6
Upvote 0
Try:
On Sheet2:
Dante Amor
AB
1Start TimeFinish Time
208:0016:00
Sheet2


Cell A2 must have the range name "s_time" and cell B2 must have the range name "f_time"

View attachment 79472

View attachment 79474

Conditional format on Sheet1:
Dante Amor
A
207:00
307:15
407:30
507:45
608:00
708:15
808:30
908:45
1009:00
1109:15
1209:30
1309:45
1410:00
1510:15
1610:30
1710:45
1811:00
1911:15
2011:30
2111:45
2212:00
2312:15
2412:30
2512:45
2613:00
2713:15
2813:30
2913:45
3014:00
3114:15
3214:30
3314:45
3415:00
3515:15
3615:30
3715:45
3816:00
3916:15
4016:30
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:A156Expression=AND($A2>=s_time,$A2<=f_time)textNO
Hey, Thanks for this.

It works to a point, but if I change the time, it does not always highlight a certain time - example, if I put 8:00 am - 1a:00 am - It only highlights upto 10:45am

Any suggestions on how to get that extra cell highlighted?

Thanks
 

Attachments

  • Capture.JPG
    Capture.JPG
    102.8 KB · Views: 6
Upvote 0
It works to a point, but if I change the time, it does not always highlight a certain time - example, if I put 8:00 am - 1a:00 am - It only highlights upto 10:45am

Check my formula carefully, you didn't put "<=".

1669375270463.png
 
Upvote 0
Solution
Hey, thanks for your quick reply - I re-did the formula, and still have the same result.
 

Attachments

  • Capture1.JPG
    Capture1.JPG
    82 KB · Views: 5
Upvote 0
I don't see your formula, I'm not sure if you did the correction correctly.

The formula works:

1669391131137.png
 
Upvote 0
Amazing - It works, I had to re make the sheet to get it to work, but thanks so much.

Thanks
 
Upvote 0

Forum statistics

Threads
1,213,562
Messages
6,114,322
Members
448,564
Latest member
ED38

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