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
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