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:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Joe[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Justin[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]John[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 1350"]
<tbody>[TR]
[TD]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! [/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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,224,824
Messages
6,181,186
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