Can VBA can be used to highlight cells in-between times, if a cell figure matches another.

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 in-between times, 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)1:00 pm
I would Like Sheet 1 to highlight a color from A6 to A38 automatically


Thanks - any help would be much appreciated
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I hope you don't have any typo. This will check Sheet 2 A2 for start time and B1 for finish time.
VBA Code:
Sub myFunction()
  Dim lRow As Integer
  lRow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
  For i = 2 To lRow
    If Worksheets("Sheet1").Cells(i, 1).Value >=  Worksheets("Sheet2").Cells(2, 1).Value And Worksheets("Sheet1").Cells(i, 1).Value <=  Worksheets("Sheet2").Cells(1, 2).Value Then
      Worksheets("Sheet1").Cells(i, 1).Interior.ColorIndex = 6
    End If
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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