Fill blanks in row 1 with nonblank values

Jdw5511

New Member
Joined
Jul 19, 2016
Messages
20
Hello,

I have values in row 1 that includes various blank cells throughout. I am needing to write a macro that fills blank cells with the value in the nonblank cell to the left. An example is shown below:

Joe Justin John

<tbody>
</tbody>

In this example, the macro would fill the first two blank cells with the name Joe, and the next three with the name Justin, up until the last cell in the row.

I am assuming what I will need is to first find the last cell in row 1, then use a combination of IF(ISblank) and offset formula.

I am using excel 2010 and any assistance that could be provided would be greatly appreciated!

<tbody>
</tbody>
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try:
Code:
Sub FillRowOneBlanks()

    Dim LC  As Long
    
    LC = Cells(1, Columns.count).End(xlToLeft).column

    With Cells(1, 1).Resize(, LC)
        .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=RC[-1]"
        .Value = .Value
    End With

End Sub
 
Last edited:
Upvote 0
Give this macro a try...
Code:
Sub FillBlanksAcross()
  On Error GoTo NoBlanks
  With Range("B1", Cells(1, Columns.Count).End(xlToLeft))
    .SpecialCells(xlBlanks).FormulaR1C1 = "=RC[-1]"
    .Value = .Value
  End With
NoBlanks:
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,932
Members
449,480
Latest member
yesitisasport

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