是否可以强制RefEdit控件选择单个单元格



excel大师!

我有一个带有RefEdit控件的用户表单,我需要在其中选择一个带有单个单元格的范围。是否可以阻止RefEdit将选择扩展到多个单元格?

尽管上述大师的评论是一次尝试:(将选定范围更改为仅第一个单元格((将RefEdit1调整为您的RefEdit名称,并使用KeyDown事件确保没有在中键入范围(

Private Sub RefEdit1_Change()
Dim x As Variant, apo As String
On Error Resume Next 'just to make sure
If InStr(1, RefEdit1.Text, "'") > 0 Then apo = "'"  'for sheetnames with spaces
If InStr(1, RefEdit1.Text, "!") > 0 Then
x = Split(RefEdit1.Value, "!")
If InStr(x(0), ":") > 0 Then x(0) = apo & Application.Substitute(Split(x(0), ":")(0), "'", "") & apo
Sheets(Application.Substitute(Split(x(0), ":")(0), "'", "")).Activate
'splitting on : for selecting multiple sheets, Activate for first selected sheet
RefEdit1.Value = x(0) & "!" & Range(x(1)).Cells(1).Address(True, True)
End If
End Sub

最新更新