Auto Fill emtpy cell till next value with VBA

winde

New Member
Joined
Nov 27, 2018
Messages
32
Hi

Is there a code to do the following?

Before
A B C D
x x x x
x x x x
x x x x
E F G H
x x x x
x x x x
I J K L
xx x x

After
A B C D
A B C D
A B C D
A B C D
E F G H
E F G H
E F G H
I J K L
I J K L

I wan to fill the "x" which are empty.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
try these codes
Code:
Sub jjj()
Dim a As Integer, b As Integer, x As Integer, y As Integer
x = Cells(Rows.Count, 1).End(xlUp).Row
y = Cells(1, Columns.Count).End(xlToLeft).Column
    For a = 1 To x
        For b = 1 To y
            If Cells(a, b) = "" Then
            Cells(a, b) = Cells(a - 1, b)
            End If
        Next b
    Next a
MsgBox "complete"
End Sub
ravishankar
 
Upvote 0
How about
Code:
Sub FillBlanks()
With ActiveSheet
   With Intersect(.UsedRange, .Range("A:D"))
      .SpecialCells(xlBlanks).Formula = "=r[-1]c"
      .Value = .Value
   End With
End With
End Sub
 
Upvote 0
try these codes
Code:
Sub jjj()
Dim a As Integer, b As Integer, x As Integer, y As Integer
x = Cells(Rows.Count, 1).End(xlUp).Row
y = Cells(1, Columns.Count).End(xlToLeft).Column
    For a = 1 To x
        For b = 1 To y
            If Cells(a, b) = "" Then
            Cells(a, b) = Cells(a - 1, b)
            End If
        Next b
    Next a
MsgBox "complete"
End Sub
ravishankar

Thanks ravi. How do i modify it if i wan it to be within a specific range and the number of rows to fill? As of now it will look for the next value but due to this, the last value doesnt get fill down since there is no next value.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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