VBA Fill spotty blank Cells Columns A-D w/Data from above it (Code Included)

LNG2013

Active Member
Joined
May 23, 2011
Messages
466
Hello,

I have spotty data in cells in Columns A-D. I want to fill all the empty cells in Columns A-D with the data that would be above the missing cells filling down, until you get the next data and then fill down for those.

I have code that will do it but I need to change the range to from end up.
Column E is fully filled out and that should be what is determined the end range.

Thank you in advance!


VBA Code:
Sub Fill()

Set Worksheet = Worksheets("Report")
Set Dataset = Worksheet.Range("A2:D50") ' This is where I need to change the range. Number of rows can be determined from end up of column E

For i = 1 To Dataset.Columns.Count
    For j = 1 To Dataset.Rows.Count
        If Dataset.Cells(j, i) = "" Then
            Dataset.Cells(j, i) = Dataset.Cells(j - 1, i)
        End If
    Next j
Next i

End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Here is an easy way to do it with no loops:
VBA Code:
Sub MyFillBlanks()
    Range("A2:D50").SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    Range("A2:D50").Value = Range("A2:D50").Value
End Sub
 
Upvote 0
So sorry I may have been poor in my wording.

The Range A2:D50 is the issue A basically need it to be A2:D - D end up, but based on E up
 
Upvote 0
OK, try this:
VBA Code:
Sub MyFillBlanks()
    Dim lr as Long
    lr = Cells(Rows.Count, "E").End(xlUp).Row
    Range("A2:D" & lr).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    Range("A2:D" & lr).Value = Range("A2:D" & lr).Value
End Sub
 
Upvote 0
Solution
OK, try this:
VBA Code:
Sub MyFillBlanks()
    Dim lr as Long
    lr = Cells(Rows.Count, "E").End(xlUp).Row
    Range("A2:D" & lr).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    Range("A2:D" & lr).Value = Range("A2:D" & lr).Value
End Sub
This worked thank you so very much!
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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