Comparing data from two set of data, highlight blank cells, count and insert average

Musto85

New Member
Joined
Mar 6, 2022
Messages
21
Platform
  1. Windows
Hi experts, I have a new challenge ahead of me and would be grateful you could help me with.

As per mini sheet below I have a set of data at the bottom (A35:U59) with cells filled with numbers in between certain time intervals.

What I would like to obtain is:
  1. Comparing the data at the bottom (A35:U59) with the data at the top (A1:R25) ensuring the relevant columns are compared with the same label row i.e. LAR01 with LAR01, LAR06 with LAR06 etc…(as in between the two data sets some can be misplaced in different columns)
  2. Highlight with colour (yellow in the example sheet) only where the corresponding time interval has no data (compared with the data at the bottom). i.e. LAR01 (B35:B59) has numbers between 6:00pm and 1:00 am (even zeros count as numbers). In the data at the top (A1:R25) in the same column with corresponding label LAR01, there are numbers missing at 9:00pm, 10:00pm and 01:00am.
  3. Subsequently count those highlighted cells (blank cells) individually by column and place this count anywhere at the bottom of each column (B27,C27 etc..)
  4. Finally, fill those highlighted cells with the average between the number in the row above and the number in the row below. (i.e. average between B16 and B19 = 3, average between B23 and B25 = 2 etc..

I’ve filled and highlighted as example until LAR07. As you will notice there might be additional columns at the bottom (A35:U59), those will need to be skipped as they're not needed.


Sorry for the explanation if it's confusing, please feel free to ask for more examples if needed.

Thank you in advance!!





Book1
ABCDEFGHIJKLMNOPQRSTUV
1LabelLAR01LAR05LAR06LAR07LAR08LAR09LAR19LBJ05LBJ06LBJ07LBJ10LBJ18LPB01LPB02LPB08LTCP01LTCP02
26:00 AM22101
37:00 AM001
48:00 AM00000
59:00 AM22100
610:00 AM22320
711:00 AM5532
812:00 PM233252
91:00 PM2543262
102:00 PM47802401363
113:00 PM35623301
124:00 PM8855198
135:00 PM811515143
146:00 PM842440653
157:00 PM4988926111526
168:00 PM5527524346642
179:00 PM34361332484
1810:00 PM33431426002255
1911:00 PM0436223055154421
2012:00 AM444304440310241
211:00 AM55324524433
222:00 AM4504404321
233:00 AM4420220611
244:00 AM201140331
255:00 AM000141600
26
27
28
29
30
31
32
33
34
35LabelLAR01LAR03LAR05LAR06LAR07LAR08LAR09LAR18LAR19LBJ05LBJ06LBJ07LBJ09LBJ10LBJ18LPB01LPB02LPB08LTCP01LTCP02
366:00 AM140015506500
377:00 AM00000
388:00 AM00000
399:00 AM700121051000
4010:00 AM105011501006050
4111:00 AM17002420550100100
4212:00 PM16508001705700141001700
431:00 PM10503030185010453502540300
442:00 PM22601804240100910270023707601000
453:00 PM126011700520124015082092004001910570
464:00 PM37005800351012002370660300019001570600
475:00 PM1890490021801795851640640029901530250
486:00 PM29109407951130250001735112014504151100
497:00 PM25001540130028001550590460150870160080
508:00 PM105075013408201730359015557651655304003400270
519:00 PM85010104315131018601180860111544010404950440
5210:00 PM2200800390300850210037501020840750850032003401000210950
5311:00 PM81505701310327515904005203002950300300509503003601550
5412:00 AM36089533606100730184551049078545011005085013003950
551:00 AM320725137041553835195077031081120015001070040400
562:00 AM1930221547351401000151008014504100
573:00 AM70037002204508809600455011000
584:00 AM0025608107500012005500010000
595:00 AM85045502950000007000
60
Sheet1
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Forgot to say...

I'm currently using the code below that works only on the data set at the top by detecting for each column first and last row with numbers, highlights the blank cells in between, puts the count of highlighted cells at the bottom and inserts the average rounded up to the nearest whole.


VBA Code:
Sub test()
    Dim a, i As Long
    With Cells(1).CurrentRegion
        ReDim a(1 To .Columns.Count - 1)
        For i = 2 To .Columns.Count
            CountBlanks .Columns(i), .Columns(i).Cells(.Rows.Count + 2)
        Next
    End With
End Sub

Sub CountBlanks(r As Range, rr As Range)
    Dim x, y, myAreas As Areas, c As Range
    x = r.Parent.Evaluate("address(min(if(isnumber(" & r.Address & "),row(" & r.Address & ")))," & r.Column & ")")
    y = r.Parent.Evaluate("address(max(if(isnumber(" & r.Address & "),row(" & r.Address & ")))," & r.Column & ")")
    If Not IsError(x) Then
        rr = r.Parent.Evaluate("countblank(" & x & ":" & y & ")")
        If x <> y Then
            On Error Resume Next
            Set myAreas = r.Parent.Range(x, y).SpecialCells(4).Areas
            On Error GoTo 0
            If Not myAreas Is Nothing Then
                For Each c In myAreas
                    c.Interior.Color = vbRed
                    c.Value = Fix((c(0) + c(c.Count + 1)) / 2)
                Next
            End If
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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