How to Move Excel Rows Automatically Based on Cell Color using VBA
Question details
The user needs a way to automatically transfer or move entire rows from one worksheet to another based on the fill color applied to specific cells.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Organizing and archiving data across multiple sheets visually, such as moving tasks that have been highlighted in yellow to a separate completed worksheet.
- Observed behavior
- Standard formulas and conditional formatting rules cannot detect formatting changes or physically move data, requiring a custom event-based VBA macro.
Ensure you have saved a backup copy of your workbook as a Macro-Enabled Workbook (.xlsm) before testing VBA scripts, as macro actions cannot be undone using the standard Undo shortcut.
Use an Event-Based VBA Macro to Move Rows
Create a VBA script within the specific worksheet module that detects cell changes, checks the cell's color index, and moves the row to a destination sheet.
Because Excel does not trigger the Worksheet_Change event strictly on a format change, this macro evaluates the row's color when the cell's value is updated or recalculated. If you need it to run strictly based on color, you will need to trigger it manually or tie it to the Worksheet_SelectionChange event.
Press Alt + F11 on your keyboard to launch the Visual Basic for Applications (VBA) editor.
In the Project Explorer pane on the left, double-click the specific worksheet name (e.g., Sheet1) where you will be changing the cell colors.
Select 'Worksheet' from the left dropdown menu above the code window, and 'Change' from the right dropdown. Write an If statement that checks if the Target cell intersects with your designated column.
Add code to check the color: If Target.Interior.ColorIndex = 6 (for yellow). Then, use Target.EntireRow.Cut and paste it to the next empty row in your destination sheet using DestinationSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1.

Use Text-Based Status Combined with Conditional Formatting
Instead of relying on cell color to trigger a macro, use a specific text value (like 'Completed') to trigger the row move, and apply Conditional Formatting to automatically color the cell.
Automate Your Spreadsheets Seamlessly with WPS Office
WPS Spreadsheet offers robust built-in support for VBA and macros, allowing you to easily automate row movements, detect cell color changes, and streamline repetitive tasks in a highly efficient environment.
- 1. Enable Macros in WPS: Open your workbook in WPS Spreadsheet, navigate to the 'Developer' tab on the ribbon, and ensure Macros are enabled for the document.
- 2. Open the VBA Editor: Click the 'Visual Basic' icon on the Developer tab or simply press Alt + F11 to launch the WPS macro editor.
- 3. Insert Your Script: Paste your row-moving VBA script into the appropriate worksheet module, and save the file to instantly deploy your automated workflow.

Frequently Asked Questions
Why isn't my row moving automatically when I change the cell fill color?
Changing a cell's formatting, such as its fill color, does not trigger the standard 'Worksheet_Change' event in Excel. To trigger an automatic move, you usually need to change the cell's actual text or numeric value alongside the color, or use a manual button to run the color-checking macro.
How do I find the exact VBA color code (ColorIndex) for a specific cell?
You can find a cell's exact color index by selecting the colored cell, opening the VBA Editor (Alt + F11), and pressing Ctrl + G to open the Immediate Window. Type '?ActiveCell.Interior.ColorIndex' and press Enter. The number returned is the exact index you need to use in your macro.
Can I move rows to another sheet using standard Excel formulas instead of VBA?
No, standard Excel formulas cannot perform physical actions like moving, cutting, or deleting rows. Formulas can only return values or display data. To physically move rows of data between worksheets, you must use VBA macros.
What happens if a user copies and pastes data with different formatting?
If a user pastes data over the target cells and changes the expected ColorIndex to an undefined shade, a color-based macro will fail to recognize the condition. This is why using standard text values paired with conditional formatting is highly recommended over color-based logic.




