johnmcp
johnmcp

Reputation: 931

How do I grab the value of a cell after entering a value?

I want to get the value of a cell after I enter some text. Basically, I highlight a cell, enter text, press return, then my code fires and I assign the value entered to a variable.

Thought it would be straightforward but I'm stumped!

Upvotes: 2

Views: 94

Answers (1)

Tim Williams
Tim Williams

Reputation: 166835

You can use a worksheet-level event handler

Dim v As Variant

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target.Cells(1), Me.Range("A1")) Is Nothing Then
        v = Target.Cells(1).Value
    End If
End Sub

Code goes in the worksheet module.

Upvotes: 4

Related Questions