VBA code to have the background color of rows and columns in an Excel active cell

Source: Internet
Author: User

In Excel, in order to enhance the contrast of the active cell, sometimes we need to modify its background color, font, font size, and so on, to differentiate and other cell contrast!

In this tutorial, let's learn how to make Excel active cells have the background color in rows and columns, first look at the figure below.

In the picture above, that is, C3 cell, is selected by the mouse, indicating that the active cell, how to do as shown above, C3 active cell row and column, the background color is color, so that we can easily observe the cell, the correct input data.

This has to be done using VBA code, as follows:

First in the Excel window, press the key combination on the keyboard: Alt + F11

This time, the VBA window pops up.

① Right-click the Sheet1 in the left list and check the code. This will pop up a small VBA input window.

② in the small window above, select Worksheet name on the left, select SelectionChange event on the right. Here's where you can enter the code, as follows:

Private Sub Worksheet_selectionchange (ByVal Target as Range)

Columns (). Interior.ColorIndex = 0

x = Activecell.column

Columns (x). Interior.ColorIndex = 13

y = ActiveCell.Row

Rows (y). Interior.ColorIndex = 13

End Sub

Finally, save the VBA window and close it, and return to the Excel window, the effect comes out.

Knowledge Extension:

Part of the code explains:

Columns (). Interior.ColorIndex = 0

x = Activecell.column

Columns (x). Interior.ColorIndex = 13

The function of the code above is to have the code with the background color listed on the active cell.

y = ActiveCell.Row

Rows (y). Interior.ColorIndex = 13

The function of the code above is the code that keeps the active cell in the background color of the row.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.