2
我有以下代码,它适用于列中的第一个值,但我需要修改代码,以便它将if语句应用于列中的所有值。现在它将结果作为40列的K列中的所有值,但我需要代码运行,以便它首先评估K2,然后K3,然后K4等请帮助!如何将宏应用于所有行?
Sub UPTRange()
Dim UPT As Range, cell As Range, result As Range
Set UPT = Range("K2:K2642")
Set result = Range("L2:L2642")
For Each cell In UPT
If cell.Value >= 40 Then
result = "40 +"
ElseIf cell.Value = (30 <= 39) Then
result = "30 - 39"
ElseIf cell.Value = (20 <= 29) Then
result = "20 - 29"
ElseIf cell.Value = (10 <= 19) Then
result = "10 - 19"
ElseIf cell.Value = (2 <= 9) Then
result = "2 - 9"
ElseIf cell.Value = (0 <= 1) Then
result = "0 - 1"
Else: cell.Value = "Error"
End If
Next
For Each cell In result
Range("L2").Value = result
Next
End Sub
嗨。感谢您的反馈,但我不认为这确实解决了问题。我能够得到一个结果到我需要的单元格中,但公式看起来并没有循环遍历k列中的所有单元格。你知道一个办法吗? – Gabi
看我上面的编辑 –