[英]Glitch when using RefEdit_Change Event in a VBA UserForm
应该发生以下情况:
1.显示带有2个RefEdit控件的UserForm
2.第一个RefEdit用于选择范围
3. RefEdit_Change事件将第二个RefEdit控件调整为范围的.offset(0,1)
到目前为止,这里是我的代码:
模块1:
Dim frmSelectXY As New frmSelectImportData
With frmSelectXY
.Show
.DoStuffWithTheSelectedRanges
End With
用户窗体:frmSelectImportData
Option Explicit
Private Type TView
IsCancelled As Boolean
xrng As Range
yrng As Range
End Type
Private this As TView
Public Property Get IsCancelled() As Boolean
IsCancelled = this.IsCancelled
End Property
Public Property Get yrng() As Range
Set yrng = this.yrng
End Property
Public Property Get xrng() As Range
Set xrng = this.xrng
End Property
'Here is where the fun happens
Private Sub RefEdit1_Change()
'RefEdit2.Value = RefEdit1.Value
If InStr(1, RefEdit1.Value, "[") <> 0 And InStr(1, RefEdit1.Value, "!") <> 0 Then
RefEdit2.Value = Range(RefEdit1.Value).offset(0, 1).Address(External:=True)
ElseIf InStr(1, RefEdit1.Value, "!") <> 0 Then
RefEdit2.Value = Range(RefEdit1.Value).offset(0, 1).Parent.Name & "!" & Range(RefEdit1.Value).offset(0, 1).Address(External:=False)
Else
RefEdit2.Value = Range(RefEdit1.Value).offset(0, 1).Address(External:=False)
End If
End Sub
Private Sub SaveBTN_Click()
Set this.xrng = Range(RefEdit1.Value)
Set this.yrng = Range(RefEdit2.Value)
If Not validate Then
MsgBox "x-values and y-values need to have the same size."
Else
Me.Hide
End If
End Sub
Function validate() As Boolean
validate = False
If this.xrng.count = this.yrng.count Then validate = True
End Function
RefEdit1_Change
应该调整RefEdit1_Change
的值,以使其在其旁边或更佳的.offest(0,1)
显示对该列的引用。
但是,事实并非如此。值不会改变。 如果RefEdit1已经更改,则用户单击进入RefEdit2后,程序将中止,而不会出现错误消息。 如果您可以取消UserForm,我也会遇到Excel的严重崩溃。 我已经通过从头开始重建UserForm并重命名了RefEdits暂时解决了该问题。 但是在某个时候它又重新出现了。 似乎这是Excel / VBA固有的问题。
有人知道如何解决此问题吗?
欢迎使用丑陋的骇客和解决方法,总比没有错误消息中止更好。
您需要将Range(RefEdit1.Value).offset(0, 1).Parent.Name in
括Range(RefEdit1.Value).offset(0, 1).Parent.Name in
'so中
="'" & Range(RefEdit1.Value).offset(0, 1).Parent.Name & "'!"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.