Fill in function

tigerzen

Board Regular
Joined
Mar 8, 2023
Messages
209
Office Version
  1. 365
Platform
  1. Windows
The desired result is on the right, I need a formula/function to fill in the gaps, the tricky part is that the formula needs to adjust when a new heading appears

Book3
ABCDE
2ProjectA 1.1ProjectA 1.1
3Project
4A 1.2ProjectA 1.2
5A 1.3ProjectA 1.3
6Project
7A 1.4ProjectA 1.4
8A 1.5ProjectA 1.5
9Project
10Project
11A 1.6ProjectA 1.6
12GovernanceB 1.1GovernanceB 1.1
13Governance
14Governance
15Governance
16B 1.2GovernanceB 1.2
17Governance
18B 1.3GovernanceB 1.3
19ConsultationC 1.1ConsultationC 1.1
20Consultation
21Consultation
22C 1.2ConsultationC 1.2
23Consultation
24C 1.3ConsultationC 1.3
25C 1.4ConsultationC 1.4
Sheet1
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
An option. Select the Range A2:A20. Ctr + G -> Specials -> Blanks -> Type =A2 -> Ctrl + Enter.
 
Upvote 0
Thanks Cubist, that works really well when the 2 columns are next to each other, sometimes my data might read Project, status, on/off track, A1.2 so the above formula won't work. Also, users will add/delete rows so need a formula that will still be able to populate.
 
Upvote 0
I'm not aware any combination of Excel functions that can accomplish this but here's a UDF.

VBA Code:
Function FillRange(rng As Range) As Variant
    Dim arr() As Variant
    Dim i As Long
    arr = rng.Value
 
    ' Loop through array to replace blank cells with the value of the previous non-blank cell
    For i = LBound(arr, 1) To UBound(arr, 1)
        If IsEmpty(arr(i, 1)) Then
            If i > LBound(arr, 1) Then
                arr(i, 1) = arr(i - 1, 1)
            End If
        End If
    Next i
 
    FillRange = arr
End Function

Book3
ABCDE
1
2ProjectA 1.1ProjectA 1.1
3Project
4A 1.2ProjectA 1.2
5A 1.3ProjectA 1.3
6Project
7A 1.4ProjectA 1.4
8MarkA 1.5MarkA 1.5
9Mark
10Mark
11A 1.6MarkA 1.6
12GovernanceB 1.1GovernanceB 1.1
13Governance
14Governance
15Governance
16B 1.2GovernanceB 1.2
17Governance
18B 1.3GovernanceB 1.3
19ConsultationC 1.1ConsultationC 1.1
20Consultation
21Consultation
22C 1.2ConsultationC 1.2
23Consultation
24C 1.3ConsultationC 1.3
25C 1.4ConsultationC 1.4
Sheet8
Cell Formulas
RangeFormula
D2:D25D2=FillRange(A2:A25)
Dynamic array formulas.
 
Upvote 0
A formula option
Fluff.xlsm
ABCDE
1
2ProjectA 1.1ProjectA 1.1
3Project
4A 1.2ProjectA 1.2
5A 1.3ProjectA 1.3
6Project
7A 1.4ProjectA 1.4
8A 1.5ProjectA 1.5
9Project
10Project
11A 1.6ProjectA 1.6
12GovernanceB 1.1GovernanceB 1.1
13Governance
14Governance
15Governance
16B 1.2GovernanceB 1.2
17Governance
18B 1.3GovernanceB 1.3
19ConsultationC 1.1ConsultationC 1.1
20Consultation
21Consultation
22C 1.2ConsultationC 1.2
23Consultation
24C 1.3ConsultationC 1.3
25C 1.4ConsultationC 1.4
Data
Cell Formulas
RangeFormula
D2:E25D2=HSTACK(SCAN(,A2:A25,LAMBDA(a,b,IF(b="",a,b))),IF(B2:B25="","",B2:B25))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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