Table of Contents
VBA or Visual Basic for Applications is a programming language used in Microsoft Office applications, such as Excel, to automate tasks and manipulate data. One useful function of VBA is the ability to fill blank cells with the value of the cell above them. This can be achieved by writing a simple code that loops through each cell in a selected range, checks if it is blank, and if so, assigns it the value of the cell above it. This can save time and effort when working with large datasets or when creating reports with missing data. By utilizing VBA, users can efficiently clean up their data and ensure consistency and accuracy in their spreadsheets.
VBA: Fill Blank Cells with Value Above
Often you may want to use VBA to fill blank cells in an Excel sheet with the values in the cells directly above them.
You can use the following basic syntax to do so:
Sub Fill_From_Above() With Range("A2:B" & Range("C" & Rows.Count).End(xlUp).Row) .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C" .Value = .Value End WithEnd Sub
This particular example will fill in all blank cells starting from cell A2 through column B to the last row that has a value in column C.
The following example shows how to use this syntax in practice.
Example: Use VBA to Fill Blank Cells with Value Above
Suppose we have the following dataset in Excel that shows the points scored during various games by various basketball players:

Suppose we would like to fill in the blank cells in columns A and B with the values in the cells above them.
We can create the following macro to do so:
Sub Fill_From_Above() With Range("A2:B" & Range("C" & Rows.Count).End(xlUp).Row) .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C" .Value = .Value End WithEnd Sub
When we run this macro, we receive the following output:

Notice that all blank cells in the Team and Player columns have been filled in with the appropriate value of the cells above them.
Note: We used xlBlanks to identify blank cells in the range and then used =R[-1]C to fill in the blanks with the value from the cell one row above it.
The end result is that we were able to fill in all blank cells with the value in the cells above them.
Cite this article
stats writer (2024). How can I use VBA to fill blank cells with the value of the cell above them?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-fill-blank-cells-with-the-value-of-the-cell-above-them/
stats writer. "How can I use VBA to fill blank cells with the value of the cell above them?." PSYCHOLOGICAL SCALES, 21 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-fill-blank-cells-with-the-value-of-the-cell-above-them/.
stats writer. "How can I use VBA to fill blank cells with the value of the cell above them?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-fill-blank-cells-with-the-value-of-the-cell-above-them/.
stats writer (2024) 'How can I use VBA to fill blank cells with the value of the cell above them?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-fill-blank-cells-with-the-value-of-the-cell-above-them/.
[1] stats writer, "How can I use VBA to fill blank cells with the value of the cell above them?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I use VBA to fill blank cells with the value of the cell above them?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
