我正在使用excel工作簿,其中一个工作表是隐藏或显示的行,具体取决于在另一个工作表中选择的选项。结构看起来像这样
A
1
2
3
4
B
1
2
3
4
C
1
2
3
4
他们可以选择隐藏A和B,A和C,A,B或C中的所有内容。用户可以选择隐藏A和B或C(他们必须在B或C之间选择)。他们还可以选择隐藏每个字母下的各个行。第1,2和3行如果选中隐藏2的选项,则所有" 2"每个字母下面的行都是隐藏的。如果他们取消选中此选项,则会再次显示所有2行。问题是" 2"将显示已隐藏字母的行。
我遇到了精神障碍,但这就是我所做的。 Psuedocode的可读性,因为现在我的代码很乱,我讨厌vba的样子。无论如何,这是一个逻辑问题而不是语法问题。
Property hiddenA As Bool get let
Property hiddenB As Bool get let
Property hiddenC As Bool get let
OptionButton1.Click()
hiddenA = true
Hide A row and all rows associated with it
OptionButton2.Click()
HiddenA = false
Show A row and all rows associated with it
OptionButton3.Click()
HiddenB = false
HiddenC = true
Show B row and all rows associated with it
Hide C row and all rows associated with it
OptionButton4.Click()
HiddenB = true
HiddenC = false
Hide B row and all rows associated with it
Show A row and all rows associated with it
CheckBox1.Click()
if CheckBox1.value = false Then
Hide all "1" rows
Else
Show all "1" rows, but keep the "1"s under already hidden letters, hidden.
This is the problem.
等等。还有用于显示/隐藏所有2,3和4行的复选框。
答案 0 :(得分:0)
粗略轮廓 - 未完成的代码......这样的事情应取消隐藏所有内容,检查每个复选框的状态,将复选框添加到范围内,并在结尾处隐藏整个范围。
'CheckBox1 is Row 1 in group
'CheckBox2 is Row 2 in group
'CheckBox3 is Row 3 in group
'CheckBox4 is Row 4 in group
'CheckBox5 is Row 5 in group
'CheckBox6 is Group A
'CheckBox7 is Group B
'CheckBox8 is Group C
'CheckBox9 is Group D
'CheckBox10 is Group E
Sub CheckBoxClick() 'Assign this to all checkboxes
Application.ScreenUpdating = False 'Turn off screen updating
ActiveSheet.Cells.EntireRow.Hidden = False 'Unhide all
Dim RngCnt As Range
Dim LastRow As Long
Dim CurRow As Long
Dim ChkBx As OLEObject
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For Each ChkBx In ActiveSheet.OLEObjects
If TypeName(ChkBx.Object) = "CheckBox" Then
Select Case ChkBx.Name
Case "CheckBox1"
If ChkBx.Value = True Then
RngCnt = Union(RngCnt, Range(Rows this chk box effects))
End If
Case "CheckBox2"
If ChkBx.Value = True Then
RngCnt = Union(RngCnt, Range(Rows this chk box effects))
End If
Case ETC, ETC, ETC to "CheckBox10"
...
End If
Next ChkBx
RngCnt.EntireRow.Hidden = True
Application.ScreenUpdating = True
End Sub