How to automatically color rows and columns in Excel

In order to clarify the content in Excel data sheet, or to highlight the data, we have the option of alternating the Excel lines or coloring the alternate cells for Excel, depending on the content that needs attention at where. Then the color displays alternately for all data objects in the table.

In case the user does not want to interleave colors but only wants to get the color when clicking first, then you can use VBA code. In this way, the data table will highlight the values ​​in rows or columns when collated, by clicking the mouse when needed. The following article will show you how to automatically match color in Excel.

  1. How to change spreadsheet color lines in Excel
  2. How to format borders and background colors for Excel tables
  3. Change color between different lines in Microsoft Excel
  4. Instructions on how to create diagonal lines in Excel box

1. How to color Excel rows when you click

Step 1:

In the Excel file you need to process, click the Developer tab on the Ribbon and choose Visual Basic or press Alt + F11 to open the VBA code editor.

How to automatically color rows and columns in Excel Picture 1

Step 2:

Displaying the Microsoft Visual Basic for Applications interface, we click on the current sheet in Project VBAProject to open the Sheet dialog.

How to automatically color rows and columns in Excel Picture 2

Next, enter the following code into the interface and press Alt + Q to turn off this interface.

 Private Sub Worksheet_SelectionChange(ByVal Target As Range) On Error Resume Next Cells.Interior.ColorIndex = 0 ActiveCell.EntireRow.Interior.ColorIndex = 8 Application.CutCopyMode = True End Sub 

How to automatically color rows and columns in Excel Picture 3

Step 3:

Back to the Excel data sheet interface when we click the mouse pointer on a cell, the row will be colored as shown below. Automatic rows are colored when you click.

How to automatically color rows and columns in Excel Picture 4

2. How to color Excel columns automatically

Step 1:

We also press Alt + F11 to open the VBA code editor. At this interface you continue to double-click on the currently open sheet in the Project VBAProject interface. Enter the code below into the VBA interface and also press Alt + Q to turn off this interface.

 Private Sub Worksheet_SelectionChange(ByVal Target As Range) On Error Resume Next Cells.Interior.ColorIndex = 0 ActiveCell.EntireColumn.Interior.ColorIndex = 8 Application.CutCopyMode = True End Sub 

How to automatically color rows and columns in Excel Picture 5

Step 2:

As a result, when you click on any one cell, the column will be colored as shown below.

How to automatically color rows and columns in Excel Picture 6

3. How to color rows and columns in Excel

When you request to color columns or rows by value, use the above two ways. In case of comparison due to data comparison, we are forced to color both in rows and columns.

Step 1:

In the VBA code entry interface, you also click on the working sheet then enter 1 of the 2 code snippets below.

 Private Sub Worksheet_SelectionChange(ByVal Target As Range) On Error Resume Next Cells.Interior.ColorIndex = 0 ActiveCell.EntireRow.Interior.ColorIndex = 8 ActiveCell.EntireColumn.Interior.ColorIndex = 8 Application.CutCopyMode = True End Sub 

Or use the code below if the code is problematic.

 Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) 'Update 20140318 Static xRow Static xColumn If xColumn <> "" Then With Columns(xColumn).Interior .ColorIndex = xlNone End With With Rows(xRow).Interior .ColorIndex = xlNone End With End If pRow = Selection.Row pColumn = Selection.Column xRow = pRow xColumn = pColumn With Columns(pColumn).Interior .ColorIndex = 6 .Pattern = xlSolid End With With Rows(pRow).Interior .ColorIndex = 6 .Pattern = xlSolid End With End Sub 

How to automatically color rows and columns in Excel Picture 7

Step 2:

After closing the interface to enter this VBA code, the user clicks any number and sees that both the column and the row passing through that cell are colored differently from the remaining cells.

How to automatically color rows and columns in Excel Picture 8

The color for the boxes when marked will depend on the ColorIndex color value table. To change the color of the column when highlighted, we need to change the number of values ​​shown for each color according to this table.

How to automatically color rows and columns in Excel Picture 9

To change the color we need to dim the interface to enter the code in VBA, then change the number of values ​​in ColorIndex = 8 to ColorIndex = 40 for example.

How to automatically color rows and columns in Excel Picture 10

Then the line color in Excel is converted to another color.

How to automatically color rows and columns in Excel Picture 11

With the type of color for the column and the user box can completely combine 2 different colors in the code.

How to automatically color rows and columns in Excel Picture 12

Excel column and row results have changed into 2 different colors as shown below.

How to automatically color rows and columns in Excel Picture 13

Another way to color rows and columns in Excel. Just enter the correct code, the row and column when clicked are all colored, easily collated, compared or searched for information in rows or columns, especially with long spreadsheets.

I wish you all success!

4 ★ | 1 Vote

May be interested

  • How to add rows and columns in ExcelHow to add rows and columns in Excel
    how to add rows and columns in excel. the article shows you 3 ways to add rows (rows) or add columns in excel.
  • How to fix column and header rows in Excel 2016How to fix column and header rows in Excel 2016
    how to fix columns and headlines in excel 2016. with an excel table with a large number of columns and rows, fixing columns and headlines is a necessary job, you can easily check. investigate and process data without confusion and waste n
  • Spacing rows and columns in Excel beautifullySpacing rows and columns in Excel beautifully
    spacing rows and columns in excel beautifully. when editing text in excel, you will come across cases where rows or columns of unequal width make your text look bad. after editing is finished, we need to readjust for v
  • How to Add Numbers Automatically in ExcelHow to Add Numbers Automatically in Excel
    there are two different ways to add numbers to a column automatically. the surest way to add automatic number ranges to excel is to use the row function. this method will ensure that cells display the correct numbering even when rows are added or deleted. the second way (without typing the formula) is to use the fill feature, this method is easier but when you delete the line the number range will be missing. let's learn how to automatically number rows, or enter consecutive numbers in columns.
  • Instructions for coloring alternating rows and columns in ExcelInstructions for coloring alternating rows and columns in Excel
    alternating colors in excel is a useful technique to make your spreadsheet more visual. learn how to use conditional formatting in excel 2007 to 2016 to easily distinguish rows and columns.
  • How to convert rows into columns and vice versa in ExcelHow to convert rows into columns and vice versa in Excel
    the following article contains detailed instructions how to convert rows into columns and vice versa in excel. assuming i have the following data table, the attributes that are in the row i want to turn into columns.
  • How to add columns, delete columns, add rows, delete rows in Word 2007, 2010, 2013, 2016How to add columns, delete columns, add rows, delete rows in Word 2007, 2010, 2013, 2016
    how to add columns, delete columns, add rows, delete rows in word 2007, 2010, 2013, 2016. the following article helps you perform the operation of inserting columns, rows or simply deleting redundant columns and rows in data tables in extremely simple ways.
  • Excel does not allow inserting additional columns and rows [FIXED]Excel does not allow inserting additional columns and rows [FIXED]
    excel does not allow inserting additional columns or rows, so you cannot continue editing the document? tipsmake has found the cause and how to fix it
  • Excel - Convert columns to rows in ExcelExcel - Convert columns to rows in Excel
    if you have an excel file and enter data in the wrong row or column or vice versa, what will you do? would you delete it and re-enter it? that takes up a lot of your time. let's see how taimienphi.vn guides you on how to convert columns into rows in excel.
  • Change the width of columns and the height of rows in ExcelChange the width of columns and the height of rows in Excel
    the default column widths and row heights in excel may not match the data you enter. you want to change the width, height of rows and columns so that data is displayed fully on cells in excel.