我很新的VBA和我想要在這裏做的可能是完全瘋狂,但請溫柔與我:-)如果在for循環
所以有點背景的陳述。我有一個項目清單(TLD)和價目表。使用下面的代碼,如果項目的名稱,產品和期限是正確的(我希望這是有道理的),我試圖從每個項目的價格表中扣除價格。
當我運行它,我得到 「編譯錯誤:否則沒有如果」
Sub add_prices()
Dim startnumber As Long
Dim endnumber As Long
Dim TLD As String
Dim Listtld As String
endnumber = Sheets("Pricelist").Application.WorksheetFunction.CountF(Range("F2:F40000")) - 1
For startnumber = 0 To endnumber
TLD = Cells(3 + startnumber, 2)
Listtld = Sheets("pricelist").Cells(2 + startnumber, 7)
Product = Sheets("pricelist").Cells(2 + startnumber, 8)
Period = Sheets("pricelist").Cells(2 + startnumber, 9)
If TLD = Listtld Then
If Product = "auto renewal" Then
If Period = "1 year" Then
Cells(3 + startnumber, 3).Value = Sheets("pricelist").Cells(2 + startnumber, 2)
Else
If Period = "2 years" Then
Cells(3 + startnumber, 3).Value = Sheets("pricelist").Cells(3 + startnumber, 2)
End If
Else
If Period = "3 years" Then
Cells(3 + startnumber, 3).Value = Sheets("pricelist").Cells(4 + startnumber, 2)
End If
Else
If Period = "4 years" Then
Cells(3 + startnumber, 3).Value = Sheets("pricelist").Cells(5 + startnumber, 2)
End If
Else
If Period = "5 years" Then
Cells(3 + startnumber, 3).Value = Sheets("pricelist").Cells(6 + startnumber, 2)
End If
End If
End If
End If
Next startnumber
End Sub
任何建議,將不勝感激
同時刪除結束時,如果在內部,如果的 –