Formula or VBA code to format certain cells based on the value.

Seeker2025

New Member
Joined
Feb 2, 2025
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Good day to everyone!

I am looking for a formula that will apply conditional formatting to a certain based on the value in that cell.

I want to create a job pickup time tracker for three shifts in each sheet each day, each with different operators, and upon the duration of the job and the region number of cells to be highlighted.

Example1

Operator-1 picks a 1-hour duration job, and the job is from the UK region

The value I enter is 1-UK1234 were

1 is the 1-hour duration of the job
UK - Is the UK region code
1234 - Is the Job ID which is not standard

Then four cells to be highlighted considering each cell a 15-minute duration.

I have also attached the template and given sample data in this and manually highlighted the cells

But I would like to have a VBA code to highlight as many cells depend on the duration and region.

Pls, refer to my attached screenshot. I wanted to attach the excel workbook, but I think only screenshot I can attach.

I want green color for the UK region jobs, Blue for the US region jobs, Orange for the AP region jobs, Yellow for Break, and Red for Leave.

Cheers.
 

Attachments

  • Screen.png
    Screen.png
    140.3 KB · Views: 20
Thanks for the sample. You could try Conditional Formatting like this.
In the mini sheet below, I copied your first 3 sample rows down to rows 8:10 for comparison and just applied my CF to B3:AG6. You would need to apply it to your full data regions.

Seeker2025_1.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG
1Morning Shift
2Name06:01 - 06:1506:16 - 06:3006:31 - 06:4506:46 - 07:0007:01 - 07:1507:16 - 07:3007:31 - 07:4507:46 - 08:0008:01 - 08:1508:16 - 08:3008:31 - 08:4508:46 - 09:0009:01 - 09:1509:16 - 09:3009:31 - 09:4509:46 - 10:0010:01 - 10:1510:16 - 10:3010:31 - 10:4510:46 - 11:0011:01 - 11:1511:16 - 11:3011:31 - 11:4511:46 - 12:0012:01 - 12:1512:16 - 12:3012:31 - 12:4512:46 - 13:0013:01 - 13:1513:16 - 13:3013:31 - 13:4513:46 - 14:00
3Name11-UK11110.75-US12340.5BR0.5-AP34562-AP12343-UK98760.25BR
4Name24-US55671-AP11221-UK09871BR
5Name3L
6Name4
7Name5
8Name61-UK11110.75-US12340.5BR0.5-AP34562-AP12343-UK98760.25BR
9Name74-US55671-AP11221-UK09871BR
10Name8L
11Name9
Mon
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B3:AG6Expression=LOOKUP("zzz",$B3:B3)="L"textNO
B3:AG6Expression=LET(last,LOOKUP("zzz",$B3:B3),AND(RIGHT(last,2)="BR",COLUMNS($B:B)-XMATCH(last,$B3:B3,,-1)<LEFT(last,LEN(last)-2)*4))textNO
B3:AG6Expression=LET(last,LOOKUP("zzz",$B3:B3),AND(MID(last,FIND("-",last)+1,2)="AP",COLUMNS($B:B)-XMATCH(last,$B3:B3,,-1)<TEXTBEFORE(last,"-")*4))textNO
B3:AG6Expression=LET(last,LOOKUP("zzz",$B3:B3),AND(MID(last,FIND("-",last)+1,2)="US",COLUMNS($B:B)-XMATCH(last,$B3:B3,,-1)<TEXTBEFORE(last,"-")*4))textNO
B3:AG6Expression=LET(last,LOOKUP("zzz",$B3:B3),AND(MID(last,FIND("-",last)+1,2)="UK",COLUMNS($B:B)-XMATCH(last,$B3:B3,,-1)<TEXTBEFORE(last,"-")*4))textNO
 
Upvote 0
Solution

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Thank you very much, Peter,
I applied the formatting that you have given. It seems only break time is working. I have given you the link below.

Could you please help me with what mistake I am making?


 
Upvote 0
I checked at home in office 2021.

Will check at office in office 365 and get back to you.

Thank you once again.
 
Upvote 0
The suggestion was written for Office 365 and will not work for Excel 2021 but possibly could be modified if it had to work in another version.
Thank you Peter,

You made my day........

It worked at office. Thank you very much.

May I get back to you if I will have any further implement.
 
Upvote 0
You are welcome. Thanks for the confirmation. (y)



If any further questions are closely related to this one, post again in this thread. Otherwise, start a new thread. :)
Hi Peter,

Sorry to bother you again,

I presented the report to my boss and she is pleased with that.

But she had one change in that. Kindly let me know whether it will be possible or not.

Just assume an operator had given 3 hours UK job at 6 am. So based on the current scenario, it is highlighted cells in green from 6 am to 9 am (B4:M3).

But if the operator wanted to go for a break in between the job, say for 30 minutes at 8 am. Then the job duration should get extended up to 9:30 am (B3:O3)

I have attached the snip and link for your reference. I will be grateful for Your help.

Thank you.

 

Attachments

  • Screenshot 2025-02-08 121859.png
    Screenshot 2025-02-08 121859.png
    17 KB · Views: 2
Upvote 0
I have not thought much about this yet, but for clarification:
Is it only a "BR" that could interrupt a job or
  1. Could the operator put one job aside part-way though and do another job then return to the original job?
  2. Could there be a short "Leave" break to interrupt a job?
  3. Could a job be interrupted by two or more short breaks?
 
Upvote 0
Yes, all the three questions were relevant.

However, my boss has not yet asked for these conditions to be implemented.

It would be a great help if you could also implement those conditions.

or at least questions 2 and 3.
 
Upvote 0

Forum statistics

Threads
1,226,439
Messages
6,191,047
Members
453,635
Latest member
gilch

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