If you want to auto fill color specific range using for loop VBA. In this article you will learn for loop in VBA meeting certain condition.
The idea is if range A1:A20 contains anything text or number then excel for loop will auto fill the blank cells.
Following is the snapshot of data in column A:
To automatically fill the color in blank cells, we need follow the below steps:
- Click on Developer tab
- From Code group, select Visual Basic
- Enter the following code in the worksheet module
For x = 1 To 20
If Selection.Value = “” Then
.Color = 65535
- After copying the code you need to run the macro by using ALT + F8 & select the macro.
In this way we can use VBA to auto fill color using for loop.