【发布时间】:2022-10-18 14:09:41
【问题描述】:
基本上,我的任务是通过以下任务在 excel 上制作用户表单。我应该做到这一点,以便它能够通过点击一个按钮, - 对数千个单元格的数据进行排序(一次接近10k),正在计算的数据类型分类如下,要合并,不会合并,合并,部分合并或被其他EA替换。 -我的最终目标是能够创建一个表格,可以通过按下按钮在其中输入这些行的计数。 - 代码还必须能够跳过隐藏的行,同时还能够计算它们。
现在,这段代码允许我计算所有 5 种类型的数量,而它无法计算其余的,例如,包括隐藏和未隐藏的总行数、隐藏行的总数、总行数其中不包含 5 种数据类型中的任何一种。
提前致谢!
Private Sub CommandButton5_Click()
Columns("P:x").ColumnWidth = 27.5
Columns("P:x").HorizontalAlignment = xlCenter
Columns("p:x").VerticalAlignment = xlCenter
Dim R As Long
Dim L As Long
Dim N As Long
Dim P As Long
Dim O As Long
Dim A As Long
Dim F As Long
Dim G As Long
Dim col As Range, i As Integer
Dim c As Long
Dim MyRange As Range
Dim myCell As Range
Dim M, range_1 As Range
Set range_1 = Range("J1").EntireColumn
With range_1
R = Worksheets("Default").Cells(Rows.Count, "A").End(xlUp).Row
For L = 2 To R
If Worksheets("Default").Cells(L, "J") = "Incorporated" And (Worksheets("Default").Rows(L).EntireRow.Hidden = False) Then
N = N + 1
End If
If Worksheets("Default").Cells(L, "J") = "To be incorporated" And (Worksheets("Default").Rows(L).EntireRow.Hidden = False) Then
M = M + 1
End If
If Worksheets("Default").Cells(L, "J") = "Won't be incorporated" And (Worksheets("Default").Rows(L).EntireRow.Hidden = False) Then
O = O + 1
End If
If Worksheets("Default").Cells(L, "J") = "Partially incorporated" And (Worksheets("Default").Rows(L).EntireRow.Hidden = False) Then
P = P + 1
End If
If Worksheets("Default").Cells(L, "J") = "Replaced by other EA" And (Worksheets("Default").Rows(L).EntireRow.Hidden = False) Then
G = G + 1
End If
Next
End With
Worksheets("default").Cells(R, "P") = ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible).Rows.Count
A = ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible).Rows.Count
Worksheets("Default").Cells(R, "s") = N
Worksheets("Default").Cells(R, "R") = M
Worksheets("Default").Cells(R, "U") = O
Worksheets("Default").Cells(R, "q") = N + M + O + P + G
Worksheets("Default").Cells(R, "T") = P
Worksheets("Default").Cells(R, "V") = G
Worksheets("Default").Cells(R, "w") = (ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible).Rows.Count - (N + M + O + P + G)) - 1
Worksheets("Default").Cells(R - 1, "s") = "EAs that are incorporated"
Worksheets("Default").Cells(R - 1, "R") = "EAs that are To be Incorporated"
Worksheets("Default").Cells(R - 1, "U") = "EAs that won't be Incorporated"
Worksheets("Default").Cells(R - 1, "q") = "EAs with an incorporation status"
Worksheets("Default").Cells(R - 1, "T") = "EAs with partially incorporated"
Worksheets("Default").Cells(R - 1, "w") = "EAs without incorporation status"
Worksheets("Default").Cells(R - 1, "P") = "Visible EAs"
Worksheets("Default").Cells(R - 1, "x") = "Non-visible EAs"
Worksheets("Default").Cells(R - 1, "V") = "EAs Replaced by other EA"
Worksheets("Default").Cells(R, "x") = R - A - 1
MsgBox A
End Sub
【问题讨论】: