How to Auto Fill Color with VBA for Loop in Microsoft Excel VBA?
Tags: toautofillcolor, vbamacros
Published: 2021-09-23 02:10:15

---
title: How to Auto Fill Color with VBA for Loop in Microsoft Excel VBA?
published: true
date: 2021-09-22 11:39:20 UTC
tags: ToAutoFillColor,VBAMacros
canonical_url: https://geekexcel.com/how-to-auto-fill-color-with-vba-for-loop-in-microsoft-excel-vba/
---

In this article, you will learn how to  **autofill color with VBA for loop** in Microsoft Excel VBA using examples. Let’s see them below!! Get the official version of  **MS Excel**  from the following link: [https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)

## Example

- Firstly, you need to  **create a sample data** with **any text or number** in **range A1:A20**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Sample-data-32.png)<figcaption>Sample data</figcaption>

- In the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Sub VBAForLoop()
    For x = 1 To 20
    Cells(x, 1).Select
        If Selection.Value = "" Then
            With Selection.Interior
                .Color = 65535
            End With
        End If
    Next x
End Sub

```

- You need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-69.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Run-the-Code-40.png)<figcaption>Run the Code</figcaption>

- Finally, you will receive the  **output ** as given below in  **Excel**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Output-32.png)<figcaption>Output</figcaption>

## End of the Line

We hope that this tutorial gives you guidelines on how to  **autofill color with VBA for loop** in Microsoft Excel. Please leave a comment in case of any  **queries,**  and don’t forget to mention your valuable  **suggestions**  as well. Thank you so much for Visiting Our Site!! Continue learning on **[Geek Excel](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Related Articles:**

- **[How To Loop Through Sheets In Excel Using VBA?](https://geekexcel.com/how-to-loop-through-sheets-in-excel-using-vba/)**
- **[Loop Through Each Worksheet & Write Text in Same Cells in Excel](https://geekexcel.com/how-to-loop-through-each-worksheet-write-text-in-same-cells-in-excel/)**
- **[How to Hide Row in Microsoft Excel 2007?](https://geekexcel.com/how-to-hide-row-in-microsoft-excel-2007/)**
- **[How to Create and Insert Auto Text Entry in Excel Office 365?](https://geekexcel.com/how-to-create-and-insert-auto-text-entry-in-excel-office-365/)**
- **[Excel VBA Loops Statements in Office 365 ~ With Examples!!](https://geekexcel.com/excel-vba-loops-statements-in-office-365-with-examples/)**