我對VBA還是比較新的,但經過一些研究後,我已經管理構建下面的選擇案例。精簡選擇案例
我想隱藏/取消隱藏單元格中指定的行數。我目前有工作,但很長篇大論,並僅限於30
Sub Toggle_Rows()
Dim Sheet As Worksheet: Set Sheet = ThisWorkbook.Worksheets("Calendar")
Change Sheet1 to the name of your sheet
Select Case CStr(Sheet.Range("NoEmployees").Value2)
Case "1"
Sheet.Rows("8:36").Hidden = True
Sheet.Rows("7:7").Hidden = False
Case "2"
Sheet.Rows("9:36").Hidden = True
Sheet.Rows("7:8").Hidden = False
Case "3"
Sheet.Rows("10:36").Hidden = True
Sheet.Rows("7:9").Hidden = False
Case "4"
Sheet.Rows("11:36").Hidden = True
Sheet.Rows("7:10").Hidden = False
Case "5"
Sheet.Rows("12:36").Hidden = True
Sheet.Rows("7:11").Hidden = False
Case "6"
Sheet.Rows("13:36").Hidden = True
Sheet.Rows("7:12").Hidden = False
Case "7"
Sheet.Rows("14:36").Hidden = True
Sheet.Rows("7:13").Hidden = False
Case "8"
Sheet.Rows("15:36").Hidden = True
Sheet.Rows("7:14").Hidden = False
Case "9"
Sheet.Rows("16:36").Hidden = True
Sheet.Rows("7:15").Hidden = False
Case "10"
Sheet.Rows("17:36").Hidden = True
Sheet.Rows("7:16").Hidden = False
ETC...
Case Else
End Select
End Sub
如果有人能解釋一個方式,我可以縮短下來並擴大行會隱藏數的選擇情況/取消隱藏然後它將不勝感激。
打敗我吧,在Kboard上太慢了:) –