[英]Returning cell value if greater than 0
Using nested formulas or VBA, I want to return ratings that are greater than 0 in each rating column for all individuals.使用嵌套公式或 VBA,我想为所有个人返回每个评分列中大于 0 的评分。 The results for each column should be right below the last filled row as shown below: Spreadsheet before calculations:
每列的结果应位于最后填充行的正下方,如下所示: 计算前的电子表格:
Rating A Ratings B Ratings C
Jane 0 -1 0
Rick 1 -2 1
Johnny -1 2 5
James 3 2 3
After:后:
Rating A Ratings B Ratings C
Jane 0 -1 0
Rick 1 -2 1
Johnny -1 2 5
James 3 2 3
Rick Johnny Johnny
1 2 5
James James James
3 2 3
Rick
1
As seen above, Rick and James have Ratings A >0 so the formula outputs the results beginning in the next empty row on Rating A Column.如上所示,Rick 和 James 的评级 A > 0,因此公式输出从评级 A 列的下一个空行开始的结果。 Same technique for Ratings B and C. Please note that this is a much smaller exempt of a larger spreadsheet.
评级 B 和 C 的技术相同。请注意,这是一个更大的电子表格的小得多的豁免。 I can't post the full spreadsheet that's thousands of rows and columns.
我无法发布包含数千行和列的完整电子表格。
First of all, as urdearboy suggested I would consider changing output format a bit and using pivot table.首先,正如urdearboy建议的那样,我会考虑稍微改变输出格式并使用数据透视表。 However if it not an option, you can try
for...next
loop.但是,如果它不是一个选项,您可以尝试
for...next
循环。
Code below will loop thought your example and collect results in a way you want, but I took a liberty to put results in separate columns, since it would be much more versatile for future use.下面的代码将循环思考您的示例并以您想要的方式收集结果,但我冒昧地将结果放在单独的列中,因为它会更加通用以备将来使用。
Sub Check_rating()
Dim x As Long
Dim ws As Worksheet
Dim counterA As Long
Dim counterB As Long
Dim counterC As Long
Set ws = Worksheets("Sheet1")
For x = 2 To Range("Table1").Rows.Count + 1
If ws.Cells(x, "B").Value > 0 Then
counterA = counterA + 1
ws.Cells(counterA, "F").Value = ws.Cells(x, "A").Value
ws.Cells(counterA, "G").Value = ws.Cells(x, "B").Value
End If
If ws.Cells(x, "C").Value > 0 Then
counterB = counterB + 1
ws.Cells(counterB, "H").Value = ws.Cells(x, "A").Value
ws.Cells(counterB, "I").Value = ws.Cells(x, "C").Value
End If
If ws.Cells(x, "D").Value > 0 Then
counterC = counterC + 1
ws.Cells(counterC, "J").Value = ws.Cells(x, "A").Value
ws.Cells(counterC, "K").Value = ws.Cells(x, "D").Value
End If
Next x
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.