在另一张表中显示隐藏列 [英] Showing hidden column in another sheet

查看:77
本文介绍了在另一张表中显示隐藏列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到如何使用VBA显示另一张表中的隐藏列。我目前正在研究VBA,而且我想为每个案例都隐藏/取消隐藏代码,但是缺少这个。任何建议?



我的(更新)代码在这里:

  Private Sub CommandButton1_Click()

'隐藏表格2
工作表(Sheet2)。Visible = False

'隐藏行22到25
Rows(22:25)。EntireRow.Hidden = True

'隐藏列E到G
列(:G)。EntireColumn.Hidden = True

'更具体的hidding(在不同的表格内)
工作表(Sheet3)。列(A:G)。EntireColumn.Hidden = True

End Sub

Public Sub UnHideAll()

Dim ws As Worksheet
对于每个ws在ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
行.Hidden = False
Columns.Hidden = False
下一个ws

End Sub

Private Sub CommandButton2_Click()
UnHideAll
End Sub


解决方案

尝试

  Sub UnHideAll()
Dim ws As Worksheet
对于每个ws在ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
ws.Rows.Hidden = False
ws.Columns.Hidden = False
下一个ws
End Sub

代码的要点是您需要符合条件如果您希望它们引用活动工作表以外的任何内容,工作表中的通过 ws。将它们前缀,让VBA知道行和列的表格。然后在按钮的代码中:

  Private Sub CommandButton1_Click()
UnHideAll
End Sub

我已经使用手动列,行和工作表进行了多次测试,以及当VBA做隐藏时,它似乎工作正常。


I am having trouble finding how to "show" a hidden column in another sheet with VBA.I am currently studying VBA and I wanted to have a hide/unhide code for every case, but this one is missing. Any suggestions?

My (updated) code is here:

Private Sub CommandButton1_Click()

    'To Hide Sheet 2
    Worksheets("Sheet2").Visible = False

    'To Hide Rows 22 to 25
    Rows("22:25").EntireRow.Hidden = True

    'To Hide Columns E to G
    Columns(":G").EntireColumn.Hidden = True

    'More specific hidding (inside a different sheet)
    Worksheets("Sheet3").Columns("A:G").EntireColumn.Hidden = True

End Sub

Public Sub UnHideAll()

    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        ws.Visible = xlSheetVisible
        Rows.Hidden = False
        Columns.Hidden = False
    Next ws

End Sub

Private Sub CommandButton2_Click()
    UnHideAll
End Sub

解决方案

Try

Sub UnHideAll()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        ws.Visible = xlSheetVisible
        ws.Rows.Hidden = False
        ws.Columns.Hidden = False
    Next ws
End Sub

The point of the code is that you need to qualify Rows and Columns by the worksheet if you want them to refer to anything other than the active sheet. Prefixing them by ws. lets VBA know what sheet the rows and columns are on. Then in the code for the button just:

Private Sub CommandButton1_Click()
    UnHideAll
End Sub

I've tested it a number of times using both manually columns, rows, and sheets, as well as when it was VBA doing the hiding, and it seems to work fine.

这篇关于在另一张表中显示隐藏列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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