![](/img/trans.png)
[英]Code to hide/unhide the userform if there is nothing to load in combobox
[英]hide modeless userform if range is nothing
此宏搜索包含錯誤的單元格范圍,如果發現有錯誤的單元格,用戶表單允許您通過 3 個不同的命令按鈕將該單元格更改為“是”、“否”或“稍后查看”。 如果沒有發現錯誤(即 CheckRange 什么都沒有),一個 msgbox 會彈出來讓你知道,然后用戶表單應該隱藏。
問題:整個宏運行完美,除了我無法隱藏用戶表單。 當沒有發現錯誤時,msg 框甚至會按計划出現。 但是用戶表單仍然存在。
Sub UserformYes_no_review()
Dim Custchk As CustomListCheck
Set Custchk = VBA.UserForms.Add(CustomListCheck.Name)
Set CheckRange = Nothing
With New CustomListCheck
On Error Resume Next
Set CheckRange = Sheets("Sheet1").Range("A1:N2000").SpecialCells(xlCellTypeFormulas, xlErrors)
On Error GoTo 0
If CheckRange Is Nothing Then
MsgBox "All items have been accounted for"
CustomListCheck.Hide
Exit Sub
Else
For Each Cell In CheckRange
Cell.Select
If VarType(ActiveCell.Value) = vbError Then
Custchk.Show vbModeless
End If
Next Cell
End If
End With
End Sub
Private Sub CommandButton1_Click()
ActiveCell.Value = "Yes"
Call UserformYes_no
End Sub
Private Sub CommandButton2_Click()
ActiveCell.Value = "No"
Call UserformYes_no
End Sub
Private Sub CommandButton3_Click()
ActiveCell.Value = "Review Later"
Call UserformYes_no
End Sub
通過將卸載我添加到每個命令按鈕私有子來解決這個問題,如下所示
Private Sub CommandButton1_Click()
ActiveCell.Value = "Yes"
Unload Me
Call UserformYes_no
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.