我有一个 excel 宏,它当前从单个单元格中读取数据,如果该单元格的值在某个数字之间,则隐藏/显示行。
我要做的是向宏添加功能,因此当给定单元格达到某个值时,它会显示/隐藏一行,然后将原始单元格值除以显示的行数,并在每一行中放置一个相等的值.
因此,如果 G10 的值为 2200,则 H 行未隐藏,然后单元格 G10 变为 1100,H10 也将变为 1100。
这是我当前的代码:
编辑:在每个 If 语句中,我想添加一些将采用 cell.Value 并在该 if 语句中变得不隐藏的行之间平均划分的内容。
Private Sub Worksheet_Calculate()
Dim rng As Range
Dim cell As Range
Set rng = Sheets("Summary").Range("G10:P10")
Application.EnableEvents = False
Sheets("Summary").Range("11:19, 23:31, 43:51, 54:62, 78:86, 90:98").EntireRow.Hidden = True
For Each cell In rng
If cell >= 2000 And cell < 4000 Then
Sheets("Summary").Range("11:11, 23:23, 43:43, 54:54, 78:78, 90:90").EntireRow.Hidden = False
Sheets("Summary").Range("12:19, 24:31, 44:51, 55:62, 79:86, 91:98").EntireRow.Hidden = True
End If
If cell.Value >= 4000 And cell.Value < 6000 Then
Sheets("Summary").Range("11:12, 23:24, 43:44, 54:55, 78:79, 90:91").EntireRow.Hidden = False
Sheets("Summary").Range("13:19, 25:31, 45:51, 56:62, 80:86, 92:98").EntireRow.Hidden = True
End If
If cell.Value >= 6000 And cell.Value < 8000 Then
Sheets("Summary").Range("11:13, 23:25, 43:45, 54:56, 78:80, 90:92").EntireRow.Hidden = False
Sheets("Summary").Range("14:19, 26:31, 46:51, 57:62, 81:86, 93:98").EntireRow.Hidden = True
End If
If cell.Value >= 8000 And cell.Value < 10000 Then
Sheets("Summary").Range("11:14, 23:26, 43:46, 54:57, 78:81, 90:93").EntireRow.Hidden = False
Sheets("Summary").Range("15:19, 27:31, 47:51, 58:62, 82:86, 94:98").EntireRow.Hidden = True
End If
If cell.Value >= 10000 And cell.Value < 12000 Then
Sheets("Summary").Range("11:15, 23:27, 43:47, 54:58, 78:82, 90:94").EntireRow.Hidden = False
Sheets("Summary").Range("16:19, 28:31, 48:51, 59:62, 83:86, 95:98").EntireRow.Hidden = True
End If
If cell.Value >= 12000 And cell.Value < 14000 Then
Sheets("Summary").Range("11:16, 23:28, 43:48, 54:59, 78:83, 90:95").EntireRow.Hidden = False
Sheets("Summary").Range("17:19, 29:31, 49:51, 60:62, 84:86, 96:98").EntireRow.Hidden = True
End If
If cell.Value >= 14000 And cell.Value < 16000 Then
Sheets("Summary").Range("11:17, 23:29, 43:49, 54:60, 78:84, 90:96").EntireRow.Hidden = False
Sheets("Summary").Range("18:19, 30:31, 50:51, 61:62, 85:86, 97:98").EntireRow.Hidden = True
End If
If cell.Value >= 16000 And cell.Value < 18000 Then
Sheets("Summary").Range("11:18, 23:30, 43:50, 54:61, 78:85, 90:97").EntireRow.Hidden = False
Sheets("Summary").Range("19:19, 31:31, 51:51, 62:62, 86:86, 98:98").EntireRow.Hidden = True
End If
If cell.Value >= 18000 Then
Sheets("Summary").Range("11:19, 23:31, 43:51, 54:62, 78:86, 90:98").EntireRow.Hidden = False
End If
Next
Application.EnableEvents = True
End Sub