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.

Instructions

    • 1

      Activate the sheet. Since an Excel workbook has several spreadsheets, so first activate it. The following code syntax activates the worksheet:
      Worksheets("mySheet").Activate

    • 2

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

    • 3

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

    • 4

      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

Related Searches

References

You May Also Like

Related Ads

Related Searches
Watch Video

#eHowHacks: The Trick to Chilling Drinks Without Watering Them Down