应采取以下措施:
1.带有2个RefEdit控件的UserForm显示为
2.第一个RefEdit用于选择范围
3. RefEdit_Change事件将第二个RefEdit控件调整为范围的.offset(0,1)。
到目前为止,我的代码如下:
Module1:
Dim frmSelectXY As New frmSelectImportData
With frmSelectXY
.Show
.DoStuffWithTheSelectedRanges
End WithUserForm: 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 FunctionRefEdit1_Change应该调整RefEdit2的值,以便它将显示对它旁边的列的引用或对它的更好的.offest(0,1)。
但事实并非如此..。价值不会改变。一旦用户单击RefEdit2 (如果RefEdit1已经更改),程序就会在没有错误消息的情况下中止。如果你放弃UserForm,我也经历过excel的硬性崩溃。我临时修复了这个问题,从零开始重新构建UserForm并重命名RefEdits。但在某种程度上却有所收获。这似乎是Excel/VBA固有的问题。
,有人知道怎么解决这个问题吗?
丑陋的黑客和解决方案是受欢迎的,任何事情都比没有错误信息的中止更好。
发布于 2019-02-11 10:33:30
你需要附上Range(RefEdit1.Value).offset(0, 1).Parent.Name in‘所以
="'" & Range(RefEdit1.Value).offset(0, 1).Parent.Name & "'!"
https://stackoverflow.com/questions/54595414
复制相似问题