[英]Automatically Hide/Unhide Column's based on value in row that is formula transposed from another worksheet
Gday All Gday全部
I am faced with a problem that I need all your help with. 我面临一个问题,需要您的帮助。 Please bear with me as I am relatively new to VBA coding and working through it.
请耐心等待,因为我是VBA编码的新手,正在研究它。
I have a complicated issue that has been partially assisted with, however with the assistance I unsurfaced more issues. 我遇到了一个复杂的问题,部分得到了帮助,但是有了这些帮助,我才发现了更多问题。
In an individual worksheet Accounts List
, the values in B2:B45
are individually determined by a data validation list with options being yes or no. 在单个工作表“
Accounts List
, B2:B45
中的值由数据验证列表单独确定,选项为“是”或“否”。 This yes or no answer is automatically transposed to a second spreadsheet being Quarter 1
at B4:AS4
. 是或否的答案会自动转换为
B4:AS4
的第二个电子表格,即Quarter 1
。 Note this is transposed by formula =transpose()
and not VBA). 请注意,这是通过公式
=transpose()
而不是VBA来=transpose()
。
I need for the macro to recognise any updates in B4:AS4
in Quarter 1
, and hide any/all columns in the range that are NOT Yes. 我需要宏来识别
Quarter 1
B4:AS4
中的所有更新,并隐藏不为Yes范围内的任何/所有列。
The current code I am utilising is: 我正在使用的当前代码是:
Private Sub Worksheet_Calculate()
Application.ScreenUpdating = False
For Each cell In Range("B4:AS4")
Select Case cell.Value <> "Yes"
Case False
cell.EntireColumn.Hidden = False
Case True
cell.EntireColumn.Hidden = True
End Select
Next cell
Application.ScreenUpdating = True
End Sub
This code does work and is achieving the result I need, HOWEVER, it renders the spreadsheet VERY slow, in that each time I enter data or make a change ANYWHERE in Quarter 1
the spreadsheet loads. 这段代码确实有效,并且达到了我需要的结果,但是,这使电子表格非常慢,因为每次我在第一
Quarter 1
输入数据或进行任何更改时,电子表格都会加载。 I need this code to be both instantaneous and not lag, as a substantial amount of source data will be inputted manually. 我需要此代码既要瞬时又要不要滞后,因为大量的源数据将手动输入。
Your help in advance is seriously appreciated!! 预先感谢您的帮助!!
UPDATE: Due to difficulties, I am happy to click a Macro button on Accounts list
to refresh Quarter 1
if need be, semi-reduce the dynamic capability but a sacrifice I am happy to take. 更新:由于困难,如果需要,我很乐意单击“
Accounts list
上的“宏”按钮来刷新Quarter 1
,半降低动态功能,但我很乐意牺牲。
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B4:AS4")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
For Each cell in Target.Cells
With cell
If .Value <> "Yes" Then
.EntireColumn.Hidden = True
Else
.EntireColumn.Hidden = False
End If
End With
Next cell
Application.EnableEvents = True
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.