Highlight the Column of the Selected Cell

Add to Favorites
This macro will highlight the column of the active cell. This will fill the column of the active cell with a solid background color and remove the color when a different cell is selected within the excel spreadsheet. Anytime you select a different cell, the new column will be highlighted. This is a great macro for zeroing in on a specific column during a presentation or just when working in a really big spreadsheet. Also, if you remove the gridlines from the spreadsheet, it can be hard to determine which column a cell is in and this will allow you to figure that out much quicker.

This macro will overwrite any previous color in the selected cell and column. That means that if you have a worksheet with a lot of background colors and you use this macro and start selecting cells, the previous background colors will disappear.

To change the color of the highlight change the number in this line of code .ColorIndex = 6.

Where to install the macro:  Worksheet

Highlight the Column of the Selected Cell

Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Static cc

If cc <> "" Then
With Columns(cc).Interior
.ColorIndex = xlNone
End With
End If

c = Selection.Column
cc = c

With Columns(c).Interior
.ColorIndex = 6
.Pattern = xlSolid
End With

End Sub







Similar Content on TeachExcel
Pass Arguments to a Macro Called from a Button or Sheet in Excel
Tutorial: How to pass arguments and values to macros called from worksheets, buttons, and anything e...
How to Create and Manage a Chart in Excel
Tutorial: In this tutorial I am going to introduce you to creating and managing charts in Excel. Bef...
Make a UserForm in Excel
Tutorial: Let's create a working UserForm in Excel. This is a step-by-step tutorial that shows you e...
Increment a Value Every X Number of Rows in Excel
Tutorial: How to increment a value, number, percent, etc. every so many rows in Excel. This tutorial...
Count the Occurrences of the Largest or Smallest Value in a Range
Tutorial: How to count the occurrence of the largest or smallest value in a range; basically, how m...
NPER Function - Calculate Number of Periods Needed for a Set of Payments in Excel
Tutorial: How to calculate the number of periods required for an investment in order to get the desi...



How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.


Similar Content
Pass Arguments to a Macro Called from a Button or Sheet in Excel
Tutorial: How to pass arguments and values to macros called from worksheets, buttons, and anything e...
How to Create and Manage a Chart in Excel
Tutorial: In this tutorial I am going to introduce you to creating and managing charts in Excel. Bef...
Make a UserForm in Excel
Tutorial: Let's create a working UserForm in Excel. This is a step-by-step tutorial that shows you e...
Excel Forum