Forum Discussion

Strout420's avatar
Strout420
Copper Contributor
Mar 20, 2020

Referencing current cell address in a formula

I would like to reference in a formula the cell address of where the cursor is currently located.  As the cursor moves to the adjacent cell (up, down, backwards, forwards) this value would change.  Being able to reference this value in a formula would allow conditions to be applied to the contents of the cell containing the formula.

 

Another way of putting it is to ask whether it is possible to reference the contents of the drop down box in the upper left corner which always displays the cell reference of where the cursor currently resides (see screen shot).  Thanks.

 

1 Reply

  • Charla74's avatar
    Charla74
    Iron Contributor

    Strout420 

     

    If you're familiar with VBA you could do this with a worksheet selection change event, along the lines of the code below.  This example enters the formula in cell H1 and basically starts with the base number of 18 plus whatever number is found in the active cell.  Obviously, you would need to adjust the formula but in principle, this code should give you what you're looking for:

     

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If ActiveCell > "" Then
    Range("H1").Formula = "=18+" & ActiveCell.Value
    Else
    Range("H1").Value = 18
    End If
    End Sub

Resources