Add data in blank cells in a column

NewToVBA1

New Member
Joined
May 22, 2011
Messages
20
I have a series of blank and non-blank data in a column. The number of blank data are fixed (for example 50) and the number of non-blank data is one. This repeats a number of times. I need to fill the blank cells with the non-blank data above it. I have used the following code. The code works fine until cell above the last non-blank data. However, it does not enter the data after the last 50 data after the last non-blank data, because it cannot find a non-blank data below. I can manualy enter a dummy data at the last 51st cell and then it works fine, but then it is not automatic.
Can anybody help?

The code is:

Sub FillEmpty()
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.Calculation = xlManual
Dim cell As Range
Dim rRange1 As Range
Set ws = ThisWorkbook.Sheets("Dummy2") 'Dummy2 is the name of the worksheet where the data is.

For Each cell In ws.Range("A3", ws.Range("A" & Rows.Count).End(xlUp))
If Trim(cell) = "" And cell.Row > 1 Then
cell.NumberFormat = cell.Offset(-1, 0).NumberFormat
cell.Value = (cell.Offset(-1, 0).Value)
End If
Next cell
Application.Calculation = xlAutomatic 'xlCalculationAutomatic
Application.ScreenUpdating = False
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

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