我有错误438消息,但无法找出原因?你有一个想法?对于每个单元格在我的范围B5:B28,我想检查字符串值,并打印一个数字相应的字符串到旁边的单元格的权利。
Public Sub RolloutStage()
Dim rng As Range
For Each rng In Worksheets("backEnd_Lost&Found").Range("B5:B28")
If Worksheets("backEnd_Lost&Found").rng.Value = "Live" Then
Worksheets("backEnd_Lost&Found").ActiveCell.Offset(0, 1).Value = 8
ElseIf Worksheets("backEnd_Lost&Found").rng.Value = "Configuration" Then
Worksheets("backEnd_Lost&Found").ActiveCell.Offset(0, 1).Value = 7
ElseIf Worksheets("backEnd_Lost&Found").rng.Value = "Testing" Then
Worksheets("backEnd_Lost&Found").ActiveCell.Offset(0, 1).Value = 6
ElseIf Worksheets("backEnd_Lost&Found").rng.Value = "Planned" Then
Worksheets("backEnd_Lost&Found").ActiveCell.Offset(0, 1).Value = 5
ElseIf Worksheets("backEnd_Lost&Found").rng.Value = "Pending" Then
Worksheets("backEnd_Lost&Found").ActiveCell.Offset(0, 1).Value = 4
ElseIf Worksheets("backEnd_Lost&Found").rng.Value = "Not planned" Then
Worksheets("backEnd_Lost&Found").ActiveCell.Offset(0, 1).Value = 3
ElseIf Worksheets("backEnd_Lost&Found").rng.Value = "No contact" Then
Worksheets("backEnd_Lost&Found").ActiveCell.Offset(0, 1).Value = 2
Else
Worksheets("backEnd_Lost&Found").rng.Value = "Not interested"
Worksheets("backEnd_Lost&Found").ActiveCell.Offset(0, 1).Value = 1
End If
Next
End Sub
2条答案
按热度按时间5cnsuln71#
这是正确的版本。谢谢
webghufk2#
有条件地填充相邻单元格
在你的密码里
rng.Value
代替ws.rng.Value
。ActiveCell
属性:使用rng
代替ws.ActiveCell
。For Each...Next循环
For Each cell In rg.Cells
行是做什么的?你可以想象在第一次迭代中,它在下面写了下面这行不可见的代码:所以在下一章中,我们将使用this cell检查值,并再次使用this cell向右边相邻的单元格写入另一个值。
等等。
进步