【发布时间】:2017-12-03 04:49:50
【问题描述】:
我有两张表格 sheet1 和 sheet2
在 sheet1 的 AX 列中,我使用公式打印了我当前的一周。我正在寻找 sheet1、T 列和 U 列,并计算两列中 1 的数量。
两列的 1 计数应粘贴到 sheet2 中,查看 AX 列中 sheet1 的周数。如果 AX 列的第 24 周,那么它应该沿着 sheet2、A 列运行 24 并粘贴 B 列中 T 的计数值和 C 列中 U 的计数值,并计算两者的百分比并粘贴到 C和 D。
我尝试了一个代码,我经常得到它为 0,我在我错的地方感到震惊。既不检查计数也不检查周数。
Sub test()
Dim col As Range
Dim row As Range
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim T As Integer
Dim U As Integer
Dim wk As String
Set sh1 = Sheets("BW")
Set sh2 = Sheets("Results")
For Each col In sh2.Columns 'This loops through all populated columns in row one
If sh2.Cells(1, col.Column).Value = "" Then
Exit For
End If
wk = sh2.Cells(1, col.Column).Value
For Each rw In sh1.Rows
If sh1.Cells(rw.row, 50).Value = "" Then
Exit For
End If
If sh1.Cells(rw.row, 50) = wk And sh1.Cells(rw.row, 20) = 1 Then
T = T + 1
End If
If sh1.Cells(rw.row, 50) = wk And sh1.Cells(rw.row, 21) = 0 Then
U = U + 1
End If
Next rw
sh2.Cells(2, col.Column) = T 'put counters into 2nd and 3rd row under each week, you can adjust this to put the number in a different cell.
sh2.Cells(3, col.Column) = U
T = 0 'reset counters to start looking at next week.
U = 0
Next col
End Sub
【问题讨论】:
-
@pnuts 对不起。我不太明白你的意思
-
您之前的许多问题都有尚未接受的答案 - 他们没有提供问题的解决方案吗?
-
@paulbica 不,它们不是我期望的解决方案。大多数我有解决方案,我已经接受并标记为绿色。
-
@paulbica 你能帮我为这种情况或上面的代码有什么问题提供答案吗?
-
我不太清楚你想要完成什么。您能否展示一个小样本,说明 sheet1 现在的外观以及 sheet2 的外观?当前数据和预期结果 - 我想复制你正在做的事情