【发布时间】:2021-10-27 11:58:38
【问题描述】:
我对 vba 编码非常陌生。 在工作表中,我试图通过检查同时列 J、K、O 中的条件来使用宏列(Q)添加一个附加列。因此,如果某些条件在每一列中传递,我希望在 Q 中输入一个值列对应的行。这是我整理的一段代码。
Option Explicit
Sub Button2_Click()
Sheet1.Activate
Dim i As Long
For i = 2 To .Cells(.Rows.Count, "B").End(xlUp).Row
'Check so that we only process non-empty cells
'(just in case there is an empty cell part-way through the data)
If Cells(i, 10).Value = "No" And Cells(i, 15) <= 0 Then
Cells(i, 17) = "Pending with employee"
Else
If Cells(i, 10).Value = "No" And Cells(i, 15) >= 0 And Cells(i, 11) = "No Action Pending" Then
Cells(i, 17) = "Pending with employee"
Else
If Cells(i, 10).Value = "No" And Cells(i, 15) >= 0 And Cells(i, 11) = "Pending With Manager" Then
Cells(i, 17) = "Pending with Manager"
Else
If Cells(i, 10).Value = "Yes" And Cells(i, 15) >= 0 And Cells(i, 11) = "No Action Pending" Then
Cells(i, 17) = "All Done"
'If Not IsEmpty(.Cells(i, "B").Value) Then
' If .Cells(i, "E").Value = "NA" Then'
'ThisWorkbook.Worksheets("CTCto TCC Conversion").Cells(i, "F").Value = "NA" '
End If
End If
End If
End If
Next i
End With
MsgBox "Column Created"
End Sub
它给我一个错误 Invalid or unqualified reference 。如果有任何错误需要纠正才能运行代码,请帮助我。
谢谢
【问题讨论】:
-
您需要一个
With ...声明供.Cells和.Rows.Count参考。或者删除那些调用前面的.以隐式引用ActiveSheet,这就是你在其他地方所做的。