VBA中带有2个条件的If语句
出错时继续下一步VBA中带有2个条件的If语句,vba,Vba,出错时继续下一步 j = Application.WorksheetFunction.Match(Strg, ws2.Range("K1:K3100"), False) result = Cells(j, 21) If (Err <> 0) Then Else If result = "Closed" Then Cells(j, 3) = "B" ws1.Select Cells(i, 22).Interior
j = Application.WorksheetFunction.Match(Strg, ws2.Range("K1:K3100"), False)
result = Cells(j, 21)
If (Err <> 0) Then
Else
If result = "Closed" Then
Cells(j, 3) = "B"
ws1.Select
Cells(i, 22).Interior.ColorIndex = 3 'Red
'copy row to the other tab
Rows(i).Select
Selection.Copy
ws3.Select
Rows(k + 2).Select
ActiveSheet.Paste
k = k + 1
ws1.Select
End If
j=Application.WorksheetFunction.Match(Strg,ws2.Range(“K1:K3100”),False)
结果=单元格(j,21)
如果(错误为0),则
其他的
如果result=“Closed”,则
单元(j,3)=“B”
ws1.选择
单元格(i,22)。Interior.ColorIndex=3'红色
'将行复制到其他选项卡
行(i)。选择
选择,复制
ws3.选择
行(k+2)。选择
活动表。粘贴
k=k+1
ws1.选择
如果结束
需要在单元格(j,3)=“B”后再添加一条if语句
A列中的条件(年份)为2016将员工ID列中不同工作表(ws1.select)中的单元格颜色设置为橙色。我想您需要这样的颜色-
If result = "Closed" Then
Cells(j, 3) = "B"
ws1.Cells(i, 22).Interior.ColorIndex = 3 'Red
If Cells(i, 1) = 2016 Then
ws1.Cells(x, y).Interior.ColorIndex = 46 'you need to specify where Employee ID column is with replacing x and y
End If
'copy row to the other tab
For Each c In ws1.Rows(i)
ws3.Cells(k + 2, c.Column) = c
Next
k = k + 1
End If
您是希望嵌套它还是希望添加它以使if为真必须满足两个条件?对于找到的任何员工,2016年必须满足真所以您希望
if result=“closed”和year=2016然后
还是希望if result=“closed”然后执行此操作
,然后检查如果年份=2016
?是否需要第二个,并为员工id(即ws1工作表)上色。。谢谢你的帮助!