Правильно, как указано в комментариях, если вы Debug
ваш код, вы увидите ту же ошибку Else Without If
. Это потому, что вы используете _
неправильно. Опять же, использование подчеркивания позволяет эффективно писать несколько строк кода, что фактически составляет одну строку. Это используется для «разделения» очень длинных отдельных строк. Я обновил ваш код ниже с некоторыми незначительными изменениями. Я не проверял это, но он компилируется.
Option Explicit
Sub Result()
Dim barang As Range
Set barang = ActiveSheet.Columns(5)
If InStr("barang", "*SF*") <> 0 Then
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]<25,IF(RC[-1]>=VLOOKUP(RC[-3],'Price List SF'!R4C1:R27C7,6,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<55,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List SF'!R4C1:R27C7,4,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=60,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List SF'!R4C1:R27C7,2,FALSE),1%,0.5%),"""")))"
ElseIf InStr("barang", "BS" & "FS") <> 0 Then
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]<5,IF(RC[-1]>=VLOOKUP(RC[-3],'Harga Bubble & Foam'!R5C1:R12C7,6,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<10,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Harga Bubble & Foam'!R5C1:R12C7,4,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=10,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Harga Bubble & Foam'!R5C1:R12C7,2,FALSE),1%,0.5%),"""")))"
ElseIf InStr("barang", "SB") <> 0 Then
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]<30,IF(RC[-1]>=VLOOKUP(RC[-3],'Harga Strapping Band RajaPack'!R4C1:R27C7,6,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<100,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Harga Strapping Band RajaPack'!R4C1:R27C7,4,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=100,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Harga Strapping Band RajaPack'!R4C1:R27C7,2,FALSE),1%,0.5%),"""")))"
ElseIf InStr("barang", "MT" & "DT" & "KT" & "CT") <> 0 Then
ActiveCell.FormulaR1C1 = _
"=IF(VLOOKUP(RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,2,FALSE)=72,IF(Sheet1!RC[-2]<360,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price L" & _
"ist MT, DT, KT, CT'!R4C1:R28C8,3,FALSE),1%,0.5%),""""))),IF(VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,2,FALSE)=144,IF(Sheet1!RC[-2]<720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,5,FALSE),1%,0.5%);IF(She" & _
"et1!RC[-2]>=1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,3,FALSE),1%,0.5%)))),IF(VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,2,FALSE)=288,IF(Sheet1!RC[-2]<1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<2880,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'P" & _
"rice List MT, DT, KT, CT'!R4C1:R28C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=2880,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,3,FALSE),1%,0.5%)))),"""")))"
Else
ActiveCell.FormulaR1C1 = _
"=IF(VLOOKUP(RC[-3],'Price List OPP Tapes'!R4C1:R42C8,2,FALSE)=12,IF(Sheet1!RC[-2]<60,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<120,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=120,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'! " & _
"R4C1:R42C8,3,FALSE),1%,0.5%),""""))),IF(VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,2,FALSE)=48,IF(Sheet1!RC[-2]<240,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<480,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=480,IF(Sheet1!RC[-1]>=" & _
"VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,3,FALSE),1%,0.5%),""""))),IF(VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,2,FALSE)=72,IF(Sheet1!RC[-2]<360,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,5,FALSE),1%" & _
"(Sheet1!RC[-2]>=720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,3,FALSE),1%,0.5%),""""))),IF(VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,2,FALSE)=144,IF(Sheet1!RC[-2]<720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3]," & _
"'Price List OPP Tapes'!R4C1:R42C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,3,FALSE),1%,0.5%),""""))),IF(VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,2,FALSE)=288,IF(Sheet1!RC[-2]<1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<" & _
"2880;IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=2880,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,3,FALSE),1%,0.5%),""""))))))))"
End If
End Sub
РЕДАКТИРОВАТЬ
Верно, поэтому в вашем коде отсутствует цикл For
, поэтому я думаю, что вы ищете ниже,Я не проверял это, но я уверен, что вы поймете логику.
Кроме того, хорошей практикой программирования является явное определение объектов рабочей таблицы, поскольку использование ActiveSheet
подвержено ошибкам пользователя.
Option Explicit
Sub Result()
Dim ws As Worksheet
Dim i As Long, lRow As Long
Set ws = ThisWorkbook.Sheets("Sheet1")
lRow = ws.Columns(5).Rows.Count
For i = 1 To lRow
With ws.Cells(i, 5)
If InStr(1, .Value, "*SF*") <> 0 Then
.FormulaR1C1 = _
"=IF(RC[-2]<25,IF(RC[-1]>=VLOOKUP(RC[-3],'Price List SF'!R4C1:R27C7,6,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<55,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List SF'!R4C1:R27C7,4,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=60,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List SF'!R4C1:R27C7,2,FALSE),1%,0.5%),"""")))"
ElseIf InStr(1, .Value, "BS") <> 0 Then
.FormulaR1C1 = _
"=IF(RC[-2]<5,IF(RC[-1]>=VLOOKUP(RC[-3],'Harga Bubble & Foam'!R5C1:R12C7,6,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<10,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Harga Bubble & Foam'!R5C1:R12C7,4,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=10,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Harga Bubble & Foam'!R5C1:R12C7,2,FALSE),1%,0.5%),"""")))"
ElseIf InStr(1, .Value, "SB") <> 0 Then
.FormulaR1C1 = _
"=IF(RC[-2]<30,IF(RC[-1]>=VLOOKUP(RC[-3],'Harga Strapping Band RajaPack'!R4C1:R27C7,6,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<100,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Harga Strapping Band RajaPack'!R4C1:R27C7,4,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=100,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Harga Strapping Band RajaPack'!R4C1:R27C7,2,FALSE),1%,0.5%),"""")))"
ElseIf InStr(1, .Value, "MT") <> 0 Then
.FormulaR1C1 = _
"=IF(VLOOKUP(RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,2,FALSE)=72,IF(Sheet1!RC[-2]<360,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price L" & _
"ist MT, DT, KT, CT'!R4C1:R28C8,3,FALSE),1%,0.5%),""""))),IF(VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,2,FALSE)=144,IF(Sheet1!RC[-2]<720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,5,FALSE),1%,0.5%);IF(She" & _
"et1!RC[-2]>=1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,3,FALSE),1%,0.5%)))),IF(VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,2,FALSE)=288,IF(Sheet1!RC[-2]<1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<2880,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'P" & _
"rice List MT, DT, KT, CT'!R4C1:R28C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=2880,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List MT, DT, KT, CT'!R4C1:R28C8,3,FALSE),1%,0.5%)))),"""")))"
Else
.FormulaR1C1 = _
"=IF(VLOOKUP(RC[-3],'Price List OPP Tapes'!R4C1:R42C8,2,FALSE)=12,IF(Sheet1!RC[-2]<60,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<120,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=120,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'! " & _
"R4C1:R42C8,3,FALSE),1%,0.5%),""""))),IF(VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,2,FALSE)=48,IF(Sheet1!RC[-2]<240,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<480,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=480,IF(Sheet1!RC[-1]>=" & _
"VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,3,FALSE),1%,0.5%),""""))),IF(VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,2,FALSE)=72,IF(Sheet1!RC[-2]<360,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,5,FALSE),1%" & _
"(Sheet1!RC[-2]>=720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,3,FALSE),1%,0.5%),""""))),IF(VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,2,FALSE)=144,IF(Sheet1!RC[-2]<720,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3]," & _
"'Price List OPP Tapes'!R4C1:R42C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,3,FALSE),1%,0.5%),""""))),IF(VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,2,FALSE)=288,IF(Sheet1!RC[-2]<1440,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,7,FALSE),1%,0.5%),IF(Sheet1!RC[-2]<" & _
"2880;IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,5,FALSE),1%,0.5%),IF(Sheet1!RC[-2]>=2880,IF(Sheet1!RC[-1]>=VLOOKUP(Sheet1!RC[-3],'Price List OPP Tapes'!R4C1:R42C8,3,FALSE),1%,0.5%),""""))))))))"
End If
End With
Next i
End Sub