再次调用列表框时,VBA列表框选择未重置



我有一些代码,其中用户必须从两列列表框中多选项目。这些项目是稍后绘制的变量,每个项目都有自己的单位(即°C、°F等(。如果用户选择了具有不同单位的项目,则会显示一条错误消息,告诉他们重新选择。

我遇到的问题是,在用户重新选择后,最初的选择似乎仍然存在,因为当生成绘图时,我可以看到这些变量正在绘图。以下是我尝试过但没有成功的东西:


If InStr(header, yUnit) = 0 Then 'this is the check to see if the selections use different units
MsgBox "Error! y variable selections contain different units. Please choose again"
Application.DisplayAlerts = False
ActiveChart.Delete 'Delete the chart which is currently being constructed
Application.DisplayAlerts = True

'Method 1:
Unload FormatChart

FormatChart.UserForm_Initialize 'FormatChart is the form in which the listbox is contained.
'UserForm_Initialize is the subroutine which constructs the listbox

FormatChart.Show

'Method 2:
With FormatChart.ListBox1
For x = 0 To .ListCount - 1
If .Selected(x) Then
.Selected(x) = False
End If
Next x
End With
FormatChart.Show
End If

'''

解决了它!我只需要使用以下内容:

FormatChart.Show
Exit Sub

我相信发生的事情是子程序将继续运行,即使在我再次显示表单后;输入";按钮,它将再次调用该子例程,可能导致它从它的前一个仍然活动的实例中获取变量,或者该子例程的多个实例正在运行,不确定。。。不管怎样,我很高兴能结束这种头痛:(

最新更新