Forum Discussion

AE7888's avatar
AE7888
Copper Contributor
Jun 08, 2023
Solved

VBA code that moves to a variable address that is contained in an ADDRESS formula

I have cell (say C1) that contains an exact address (say $F$20 for example) using the ADDRESS function.   I would like VBA code to move the cursor to that address.   But each time the VBA code is u...
  • NikolinoDE's avatar
    Jun 08, 2023

    AE7888 

    To move the cursor to the address contained in cell C1, you can use the Range object in VBA. Since the value in cell C1 changes dynamically, you need to read the value from cell C1 each time the VBA code is executed.
    Here is an example VBA code that moves the cursor to the address in cell C1:

     

    Sub MoveToAddress()
        Dim address As String
        address = Range("C1").Value ' Read the address from cell C1
        
        Range(address).Select ' Move to the address
    End Sub

     

    In this code, the Range("C1").Value statement retrieves the value (address) from cell C1, and then the Range(address).Select statement selects that range, effectively moving the cursor to that address.
    You can run the MoveToAddress macro each time you want to move the cursor to the updated address in cell C1.

Resources