Clearing contents in an adjacent cell based on the value in the cell to the right or left - Help Please

Joshuab712

New Member
Joined
Nov 18, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello all, I am in need of a solution. I am running a report on the total amount of units available during a 24 hour period. The output looks like:

Unit0:00:15:30:451:00:152:303:4542:00:155:306:4573:00:158:309:45104:00:1511:3012:45135:00:1514:3015:45166:00:1517:3018:45197:00:1520:3021:45228:00:1523:3024:45259:00:1526:3027:452810:00:1529:3030:453111:00:1532:3033:453412:00:1535:3036:453713:00:1538:3039:454014:00:1541:3042:454315:00:1544:3045:454616:00:1547:3048:454917:00:1550:3051:455218:00:1553:3054:455519:00:1556:3057:455820:00:1559:3060:456121:00:1562:3063:456422:00:1565:3066:456723:00:1568:3069:4570
B13-01000000000000111111111111111111111111111111111111111111111111111100000000000000000000000000000000
B13-02000000000000000011111111111111111111111111111111111111111111111111110000000000000000000000000000
B13-03000000000000000001111111111111111111111111111111111111111111111111111110000000000000000000000000
B13-06000000000000000011111111111111111111111111111111111111111111111111111100000000000000000000000000
B13-07000000000000000000000000111111111111111111111111111111111111111111111111111100000000000000000000
B13-08000000000000000000000000111111111111111111111111111111111111111111111111111100000000000000000000
B13-09000000000000000000000000111111111111111111111111111111111111111111111111111100000000000000000000
B13-10000000000000000000000000011111111111111111111111111111111111111111111111111110000000000000000000
B13-11000000000000000000000000001111111111111111111111111111111111111111111111111111000000000000000000
B10-12000000000000000000000000000011111111111111111111111111111111111111110000000000000000000000000000

The furthest left column represents a shift name. The top row represents 24 hours of time in 15 min increments. I have a simple sum formula at the bottom which adds each column and outputs a total "Shifts working" per every 15 mins. I.E. B10-12 (bottom row) works 07:00 - 16:45, with the "1" representing the time at work, "0" representing the time not working.

The issue is that the output is 15 mins over on the front and back end. I.E. if the shift is scheduled for 10 hours I can't count the first 15 mins and the last 15 mins per shift. With the example above I would need B10-12 to actually show that it is worked from 07:15 - 16:30. I need to remove the "1" at the beginning and end of each sequence of "1's". This would give me an accurate amount of total units available per 15 min time frame. I am having a significant amount of difficulty solving the problem and any help you all can provide will be greatly appreciated. Thank you all for your time and considerations.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hello all, I am in need of a solution. I am running a report on the total amount of units available during a 24 hour period. The output looks like:

Unit0:00:15:30:451:00:152:303:4542:00:155:306:4573:00:158:309:45104:00:1511:3012:45135:00:1514:3015:45166:00:1517:3018:45197:00:1520:3021:45228:00:1523:3024:45259:00:1526:3027:452810:00:1529:3030:453111:00:1532:3033:453412:00:1535:3036:453713:00:1538:3039:454014:00:1541:3042:454315:00:1544:3045:454616:00:1547:3048:454917:00:1550:3051:455218:00:1553:3054:455519:00:1556:3057:455820:00:1559:3060:456121:00:1562:3063:456422:00:1565:3066:456723:00:1568:3069:4570
B13-01000000000000111111111111111111111111111111111111111111111111111100000000000000000000000000000000
B13-02000000000000000011111111111111111111111111111111111111111111111111110000000000000000000000000000
B13-03000000000000000001111111111111111111111111111111111111111111111111111110000000000000000000000000
B13-06000000000000000011111111111111111111111111111111111111111111111111111100000000000000000000000000
B13-07000000000000000000000000111111111111111111111111111111111111111111111111111100000000000000000000
B13-08000000000000000000000000111111111111111111111111111111111111111111111111111100000000000000000000
B13-09000000000000000000000000111111111111111111111111111111111111111111111111111100000000000000000000
B13-10000000000000000000000000011111111111111111111111111111111111111111111111111110000000000000000000
B13-11000000000000000000000000001111111111111111111111111111111111111111111111111111000000000000000000
B10-12000000000000000000000000000011111111111111111111111111111111111111110000000000000000000000000000

The furthest left column represents a shift name. The top row represents 24 hours of time in 15 min increments. I have a simple sum formula at the bottom which adds each column and outputs a total "Shifts working" per every 15 mins. I.E. B10-12 (bottom row) works 07:00 - 16:45, with the "1" representing the time at work, "0" representing the time not working.

The issue is that the output is 15 mins over on the front and back end. I.E. if the shift is scheduled for 10 hours I can't count the first 15 mins and the last 15 mins per shift. With the example above I would need B10-12 to actually show that it is worked from 07:15 - 16:30. I need to remove the "1" at the beginning and end of each sequence of "1's". This would give me an accurate amount of total units available per 15 min time frame. I am having a significant amount of difficulty solving the problem and any help you all can provide will be greatly appreciated. Thank you all for your time and considerations.
Hello,

You could write a formula in a cell: next to/below the output total.

If counting how many 1’s then

=SUM(B1:B12)-2

{You would get some minus values: so

=IF(SUM(B4:B15)=0,0,SUM(B1:B12)-2)

For counting the total time just add *15 at the end to give tou the total minutes; or *15/60 to give you the total hours worked.
 
Upvote 0
Hello,

You could write a formula in a cell: next to/below the output total.

If counting how many 1’s then

=SUM(B1:B12)-2

{You would get some minus values: so

=IF(SUM(B4:B15)=0,0,SUM(B1:B12)-2)

For counting the total time just add *15 at the end to give tou the total minutes; or *15/60 to give you the total hours worked.
Thank you for responding, I was hoping for a VBA formula that would remove the "1"'s at the end of the series that I could copy and paste as I run new reports, since this won't be a static sheet.
 
Upvote 0
Thank you for responding, I was hoping for a VBA formula that would remove the "1"'s at the end of the series that I could copy and paste as I run new reports, since this won't be a static sheet.
Hello,

I put a list of, 0 & 1s, in row 1. a1 to p1 a group of is in the middle then 0s on either end.

VBA Code:
Dim i As Integer
Dim rng As Range, cell As Range
Set rng = Range("a1:p1")   'the range of your last row
i = 1
Do Until Range("a2").Value = 1     'A2 is any cell unused in your workbook
If Cells(1, i).Value = 1 Then
    Cells(1, i).Value = 0
        Range("a2").Value = Range("a2").Value + 1
        End If
        i = i + 1
Loop          
           ' now you do the opposite
i = 16      '16 is the last column in the range - P1 is the 16th column
Do Until Range("a3").Value = 1       'A2 is any cell unused in your workbook
If Cells(1, i).Value = 1 Then
    Cells(1, i).Value = 0
        Range("a3").Value = Range("a3").Value + 1
        End If
        i = i - 1
Loop
Range("a2").Value = 0
Range("a3").Value = 0          'clears cells A2 & A3 for the next time

Hope this solves your problem.

Jamie
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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