美好的一天,
我正在尝试将多个IF语句插入到宏中,但是在" 50"说"预期结束IF声明"。我从来没有通过宏来嵌套if语句,有人可以建议最好的方法吗?谢谢 也许我应该有其他等等...类似于其他编码语言(c ++,java等)?
Sub Step9_IF_1()
Dim strFirstFile As String
Dim wbk1 As Workbook
Dim wbkLookup As Workbook
Dim clLookup As Range
Dim clDest As Range
Dim rws As Long
strFirstFile = "Z:\AR\AR PROGRESS\2014\MENACA REPORTS\0MENACA Working File\AR Working File\UAE\Working File - UAE.xlsx"
Set wbk1 = Workbooks.Open(strFirstFile)
With wbk1.Sheets("sheet1")
Set clDest = .Range("YC1")
End With
If clLookup.Offset(1, 0) <> vbNullString Then
rws = Range(clLookup, clLookup.End(xlDown)).Rows.Count
Set clDest = clDest.Resize(rws, 1)
End If
clDest.Formula = "=IF(ClDest<>70,C2,IF(ISNUMBER(SEARCH("*PD*",B2)),"50",IF(ISNUMBER(SEARCH("*OD*",B2)),"50",IF(ISNUMBER(SEARCH("*OC*",B2)),"50",IF(ISNUMBER(SEARCH("*OF*",B2)),"50",IF(ISNUMBER(SEARCH("*PC*",B2)),"50",IF(ISNUMBER(SEARCH("*MS*",B2)),"50","70")))))))"
clDest.Value = clDest.Value ' Convert to value
wbk1.Close True
MsgBox ("IF Step 1 - Completed!!")
End Sub
答案 0 :(得分:0)
没关系,我设法回答了这个问题 标记答案以供将来参考,对于需要指导的朋友们来说:)
Sub Step9_IF_1()
Dim strFirstFile As String
Dim wbk1 As Workbook
Dim wbkLookup As Workbook
Dim clLookup As Range
Dim clDest As Range
Dim rws As Long
strFirstFile = "C:\Users\hayekn\Desktop\IF Statement.xlsx"
Set wbk1 = Workbooks.Open(strFirstFile)
With wbk1.Sheets("sheet1")
Set clDest = .Range("L2")
Set clLookup = .Range("C2")
End With
If clLookup.Offset(1, 0) <> vbNullString Then
rws = Range(clLookup, clLookup.End(xlDown)).Rows.Count
Set clDest = clDest.Resize(rws, 1)
End If
clDest.Formula = "=IF(" & clLookup.Address(False, False) & " <>70," & clLookup.Address(False, False) & ",IF(--ISNUMBER(SEARCH({""*PD*"",""*OD*"",""*OC*"",""*OF*"",""*PC*"",""*MS*""}," & clLookup.Address(False, False) & ")),""50"",""70""))"
clDest.Value = clDest.Value ' Convert to value
wbk1.Close True
MsgBox ("IF Step 1 - Completed!!")
End Sub