限制宏以设置文本框的范围

时间:2018-02-02 17:22:55

标签: excel-vba vba excel

我正在尝试将一系列单元格链接到文本框,唯一的问题是如果我编辑文本框,它将在任何单元格中写入。我想将该能力限制在特定范围(“C4到C11”)。这是我的代码:

Dim PreviousCell As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

   If Target.Column = 3 Then ActiveSheet.TextBox1.Text = Target



       If Not PreviousCell Is Nothing Then
       Debug.Print PreviousCell.Address
       End If

       Set PreviousCell = Target ' This needs to be the last line of code.

End Sub



Private Sub TextBox1_Change()

ActiveCell.Value = TextBox1

End Sub

1 个答案:

答案 0 :(得分:1)

Private Sub TextBox1_Change()

If ActiveCell.Column = 3 Then ActiveCell.Value = TextBox1

End Sub