Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

excel - Auto call text box when cell is selected in Column B

I want when I select a cell in Column B to be connected automatically in the text box And I created a code that does not work automatically Asking, I want to make this code automatic without pressing the button

Private Sub CommandButton1_Click()

   With Me
 
       .TextBox1.Value = Cells(ActiveCell.Row, "B").Value
     
   End With

End Sub
question from:https://stackoverflow.com/questions/65939486/auto-call-text-box-when-cell-is-selected-in-column-b

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Selection Change Changing Text Box Value

  • Put the following into the sheet module (e.g. Sheet1) of the worksheet where the text box is located.

The Code

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    Const sCol As String = "B"
    
    Dim rg As Range: Set rg = Intersect(Columns("B"), Target)
    If Not rg Is Nothing Then
        TextBox1.Value = rg.Cells(1).Value
    End If
    
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...