我正在使用Office 365,并且正在为使用excel 2016的用户创建WB。我的代码在列的所有单元格的最后一行中插入“ IFS”公式。问题是IFS在2016年不可用,因此代码对他们来说失败了,但对我有用。有没有办法更改以下代码以使其在2016年工作?当他们运行宏时,会得到#NAME吗?
Dim Lastrow As Long
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("G2").Select
ActiveCell.FormulaR1C1 = _
"=IFS(RC[-2]=""2nd Shift 1.05"",""2"", RC[-2]=""2nd Shift
Overtime"",""2"",TRUE,"""")"
Range("G2").Select
Selection.AutoFill Destination:=Range("G2:G" & Lastrow)
Range("E2").Select
End Sub
答案 0 :(得分:0)
您的代码可以缩短为:
Dim Lastrow As Long
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("G2:G" & Lastrow).Formula = "=IF(OR(E2 = ""2nd Shift 1.05"",E2=""2nd Shift Overtime""),2,"""")"
答案 1 :(得分:0)
Dim LastCall As Long
Dim y As Long
LastCall = Range("A" & Rows.Count).End(xlUp).Row
For y = 2 To LastCall
If Range("E" & y).Value = "2nd Shift 1.05" Then
Range("G" & y).Value = "2"
End If
Next y
LastCall = Range("A" & Rows.Count).End(xlUp).Row
For y = 2 To LastCall
If Range("E" & y).Value = "2nd Shift Overtime" Then
Range("G" & y).Value = "2"
End If
Next y
End Sub