因此,我有多张有关其信息的表格。我需要将这些工作表平均分配给多个人。但是我需要将其除以列表的长度。例如: 工作表1有15行 工作表2有41行 表格3有32行
如果我有5个人,则总行数为88,即每人17.6。四舍五入到整数将是每人17。所以我正在寻找要做的就是按表和按行划分。例: 第1个人将获得工作表1第1-15行和工作表2第1行和第2行 第2个人将获得工作表2第3-20行 等等...
这是我到目前为止所拥有的。
Staff = InputBox("How many people will this be divided among?", "Split")
ReDim Person(1 To Staff)
ReDim SNarray(1 To Sheets.Count)
For i = 1 To Sheets.Count
SNarray(i) = Sheets(i).Name
Next
ReDim RowCounts(1 To Sheets.Count)
For i = 1 To Sheets.Count
Sheets(SNarray(i)).Activate
RowCounts(i) = Cells(Rows.Count, 1).End(xlUp).Row
Next
For i = 1 To Sheets.Count
Total = Total + RowCounts(i)
Next
Total = (Total - 2) / Staff
Total = Int(Total)
答案 0 :(得分:0)
尝试
Sub test()
Dim Ws As Worksheet
Dim r As Long, i As Integer, Staff As Integer
Staff = InputBox("How many people will this be divided among?", "Split")
For i = 1 To Staff
Set Ws = Sheets(i)
With Ws
r = .Range("a" & Rows.Count).End(xlUp).Row
Total = Total + r - 1
End With
Next
Total = Total / Staff
Total = Int(Total)
MsgBox Total
End Sub