取消隐藏非常隐藏的Excel VBA [英] Unhiding very hidden sheet Excel VBA

查看:860
本文介绍了取消隐藏非常隐藏的Excel VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个用户表单,该表单将根据用户表单上组合框的值取消隐藏特定的工作表。在工作簿中有3个不同的工作表非常隐藏。组合框填充3个选项,每个隐藏表单一个。我正在使用select case来使正确的表单可见(最终会有超过3张/选项),示例代码如下(位于用户窗体代码窗口中):

I am trying to create a user form that will unhide a specific worksheet based on the value of the combo box on the user form. There are 3 different worksheets that are " very hidden" in the workbook. The combo box is populated with 3 choices, one for each hidden sheet. I am using select case to make the correct sheet visible (Eventually there will be many more than 3 sheets/options. Sample code follows (located in the user form code window):

Private Sub NextButton_Click()

Select Case ComboBox
    Case ComboBox.ListIndex = 0
        Sheets(1).Visible = True
    Case ComboBox.ListIndex = 1
        Sheets(2).Visible = True
    Case ComboBox.ListIndex = 2
        Sheets(3).Visible = True
End Select
Unload UserForm
End Sub

我点击下一个按钮,userform卸载,但是表格不会变得可见,VBA也没有出现任何错误,请让我知道,如果我需要提供更多的信息。

I click the next button, the userform unloads, but the sheets does not become visible. VBA brings up no errors either. Please let me know if I need to provide any more information.

Nik

推荐答案

你的case语句是不正确的,你应该告诉它在第一部分要测试什么值,然后再指定值,参见关于VBA中的案例的网络技术

Your case statement is incorrect. You should tell it what value to test in the first part, then specify the values later. See Tech on the Net article about Case in VBA.

Private Sub NextButton_Click()

Select Case ComboBox.ListIndex
    Case 0
        Sheets(1).Visible = True
    Case 1
        Sheets(2).Visible = True
    Case 2
        Sheets(3).Visible = True
End Select
Unload UserForm
End Sub

这是大多数编程语言中的case语句如何工作。

This is how case statements in most programming languages work.

但是,由于 ComboBox.ListIndex 是一个int,你可以根据这个说明来显示什么表,你可以简化整个事情并删除case语句。这个假设是索引匹配,在这个例子中它们是相同的。

However, since ComboBox.ListIndex is an int, and you're telling it what sheet to show based on that, you could simplify the whole thing and drop the case statement. This presumes the indexes match up, which they do in your example.

Private Sub NextButton_Click()  
Sheets(ComboBox.ListIndex+1).Visible = True
Unload UserForm
End Sub

这篇关于取消隐藏非常隐藏的Excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆