How to Get the Address of a Selection in VBA


When programming in VBA, you may find it necessary to retrieve the address of the cell selection for the code. For instance, if you need to change the font color, the selection address of the cell is necessary. Selection a cell address in VBA is performed using only a few steps.

  • Activate the sheet. Since an Excel workbook has several spreadsheets, so first activate it. The following code syntax activates the worksheet:

  • Assign a variable for the active cell address. The following code retrieves the active cell column and row pair:
    myAddress = ActiveCell.Address(False, False)

  • Set a value for the active cell. The following code sets the column header "Customer" into the active cell:
    ActiveCell.Value = "Customer"

  • Display the active cell and its value. The following code displays "Customer" and the address:
    MsgBox "Cell address is: " & myAddress & " and the value is: " & ActiveCell.Value


Promoted By Zergnet


You May Also Like

Read Article

Geek Vs Geek: Which Crowdfunded Projects Make the Cut?

What's for Dinner, Pinner?
Get recipes based on your pins!