-1

フィードバックをお寄せいただきありがとうございます。言語をより読みやすい形式で書く方法を理解するために、コンサルティングの助けを得ることができました。数式が正しく機能しないという問題がまだあります。

ここに私のVBAコードがあります:

'ENVIRONMENTAL - RIDER BERKLEY SURETY GROUP PREMIUM
    Range("EnviroBerkley_Grand_Total").Select
         '->>>>>>>>>>> InsertRows ---- >>>>>>>>>>>>>
          iRow = ActiveCell.Row
          getRows = 7
          nRows = getRows
          i = iRow - 1 'first row for insertion
          Rows(i & ":" & i + nRows - 1).Insert
         '<<<<<<<<END Insert Rows----------<<<<<<<<<<
    Range("EnviroBerkley_Grand_Total").Select
    ActiveCell.Offset(-15, 0).Rows("1:7").EntireRow.Select
    Selection.Copy
    ActiveCell.Offset(7, 0).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "Rider"
    ActiveCell.Offset(1, 0).Range("A1").Select
    Range("EnviroBerkley_Grand_Total").Select
    ActiveCell.Offset(-7, 2).Range("A1").Select


'FIRST 100,000 (100)
ActiveCell.FormulaR1C1 = _
    "=IF(EnviroCalculate_Premium_Using_Bond_Amount=""Y"",IF(R[-1]C[-2]<>""Original"",(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<100000,((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))-((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-3]C))/1000)*R11C2,0))," & _
    "(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<100000,(Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))/1000)*R11C2,100))),IF(ActiveCell.Offset(R[-1]C[-2])<>""Original"",(IF((((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<100000," & _
    "(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))-((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-3]C))/1000)*R11C2,0)),(IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<100000,(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))/1000)*R11C2,100))))"
ActiveCell.Offset(1, 0).Range("A1").Select

'NEXT 400,000 (400)
ActiveCell.FormulaR1C1 = _
    "=IF(EnviroCalculate_Premium_Using_Bond_Amount=""Y"",IF(R[-2]C[-2]<>""Original"",(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<100000,0,IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>500000,0,(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))" & _
    "-(Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-3]C))/1000)*R11C2))),(IF((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C)*R11C2)<100000,0,IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>500000,400,((((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))/1000)" & _
    "-1000)*R11C2))))),IF(R[-2]C[-2]<>""Original"",(IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<100000,0,IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>500000,0,(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))" & _
    "-(Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-3]C))/1000)*R11C2))),(IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<100000,0,IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>500000,400," & _
    "(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))/1000)-1000)*R11C2))))))"
ActiveCell.Offset(1, 0).Range("A1").Select

'NEXT 2,000,000 (2000)
ActiveCell.FormulaR1C1 = _
    "=IF(EnviroCalculate_Premium_Using_Bond_Amount=""Y"",IF(ActiveCell.Offset(R[-3]C[-2])<>""Original"",(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<500000,0,IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>2000000,0," & _
    "(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))-(Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-3]C))/1000)*R11C2))),(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<500000,0,IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>500000,2000," & _
    "(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))/1000)-5000)*R11C2))))),IF(R[-3]C[-2]<>""Original"",(IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<500000,0,IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>2000000,0," & _
    "((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))-(Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-3]C))/1000)*R11C2))),(IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<100000,0,IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>500000,2000," & _
    "((((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))/1000)-1000)*R11C2))))))"
ActiveCell.Offset(1, 0).Range("A1").Select

'NEXT 2,500,000 (2500)
ActiveCell.FormulaR1C1 = _
    "=IF(EnviroCalculate_Premium_Using_Bond_Amount=""Y"",IF(R[-4]C[-2]<>""Original"",(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<2000000,0,IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>5000000,0,(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))" & _
    "-(Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-3]C))/1000)*R11C2))),(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<2000000,0,IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>5000000,2500,((((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))/1000)-20000)*R11C2)))))," & _
    "IF(R[-4]C[-2]<>""Original"",(IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<2000000,0,IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>2500000,0,(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))-(Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-3]C))" & _
    "/1000)*R11C2))),(IF((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<100000,0,IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>2500000,2500,((((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))/1000)-1000)*R11C2))))))"
ActiveCell.Offset(1, 0).Range("A1").Select

'NEXT 2,500,000 (2500)
ActiveCell.FormulaR1C1 = _
    "=IF(EnviroCalculate_Premium_Using_Bond_Amount=""Y"",IF(ActiveCell.Offset(R[-5]C[-2])<>""Original"",(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<5000000,0,IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>7500000,0,(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))" & _
    "-(Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-3]C))/1000)*R11C2))),(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<5000000,0,IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>7500000,2500,((((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C)/1000))-50000)*R11C2)))))," & _
    "IF(R[-5]C[-2]<>""Original"",(IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<5000000,0,IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>7500000,0,((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))-(Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-3]C))/1000)*R11C2)))," & _
    "(IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<100000,0,IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>5000000,2500,((((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))/1000)-1000)*R11C2))))))"
ActiveCell.Offset(1, 0).Range("A1").Select

'OVER 7,500,000 (7500)
ActiveCell.FormulaR1C1 = _
    "=IF(EnviroCalculate_Premium_Using_Bond_Amount=""Y"",IF(R[-6]C[-2]<>""Original"",(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<7500000,0,IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>7500000,(((Range(EnviroBondAmountGrandTotal)..ActiveCell.Offset(R[-2]C))" & _
    "-(Range(EnviroBondAmountGrandTotal)..ActiveCell.Offset(R[-3]C))-*R11C2)/1000),(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))-(EnviroBondAmountGrandTotal.ActiveCell.Offset(R[-3]C))*R11C2)/1000)))),(IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<7500000,0," & _
    "IF(((Range(EnviroBondAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>7500000,((((Range(EnviroBondAmountGrandTotal).Select.ActiveCell.Offset(R[-2]C))*R11C2)-7500000)/1000))))),IF(R[-6]C[-2]<>""Original"",(IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)<7500000,0," & _
    "IF(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)>7500000,(((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))-(Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-3]C))*R11C2)/1000),(((Range(EnviroContractAmountGrandTotal).Select.ActiveCell.Offset(R[-2]C))-(Range(EnviroContractAmountGrandTotal).Select.ActiveCell.Offset(R[-3]C))" & _
    "*R11C2)/1000)))),IF(((Range(EnviroContractAmountGrandTotal).Select.ActiveCell.Offset(R[-2]C))*R11C2)<7500000,0,IF(((Range(EnviroContractAmountGrandTotal).Select.ActiveCell.Offset(R[-2]C))*R11C2)>7500000,((((Range(EnviroContractAmountGrandTotal).ActiveCell.Offset(R[-2]C))*R11C2)-7500000)/1000)))))"
ActiveCell.Offset(1, 0).Range("A1").Select

IFステートメントとしても書いてみました:

 'ENVIRONMENTAL - RIDER BERKLEY SURETY GROUP PREMIUM
    Range("EnviroBerkley_Grand_Total").Select
         '->>>>>>>>>>> InsertRows ---- >>>>>>>>>>>>>
          iRow = ActiveCell.Row
          getRows = 7
          nRows = getRows
          i = iRow - 1 'first row for insertion
          Rows(i & ":" & i + nRows - 1).Insert
         '<<<<<<<<END Insert Rows----------<<<<<<<<<<
    Range("EnviroBerkley_Grand_Total").Select
    ActiveCell.Offset(-15, 0).Rows("1:7").EntireRow.Select
    Selection.Copy
    ActiveCell.Offset(7, 0).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "Rider"

ActiveCell.Offset(1, 0).Range("A1").Select
Range("EnviroBerkley_Grand_Total").Select
ActiveCell.Offset(-7, 2).Range("A1").Select

 'FIRST 100,000 (100)
ActiveCell.Select
    If EnviroCalculate_Premium_Using_Bond_Amount = "Y" Then
        If ActiveCell.Offset.Range(-1, -2) <> "Original" Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 100000 Then ActiveCell = 0
                If ((Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) - Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 100000 Then
                ElseIf (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) / 1000) * R11C2 Then ActiveCell = 100
        If (ActiveCell.Offset(-1, -2)) <> "Original" Then
            If (Range("EnviroContractAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 100000 Then
                If (Range("EnviroContractAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) - Range("EnviroContractAmountGrandTotal").Select.ActiveCell.Offset(-3, 0) / 1000) * R11C2 Then ActiveCell = 0
            If (Range("EnviroContractAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 100000 Then
                ElseIf (Range("EnviroContractAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) / 1000) * R11C2 Then ActiveCell = 100
    End If
    End If
    End If
    End If
    End If
    End If
    End If
ActiveCell.Offset(1, 0).Range("A1").Select

'NEXT 400,000 (400)
ActiveCell.Select
    If EnviroCalculate_Premium_Using_Bond_Amount = "Y" Then
        If ActiveCell.Offset(-2, -2) <> "Original" Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 100000 Then ActiveCell = 0
                If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) > 500000 Then ActiveCell = 0
                ElseIf ((Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) - Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 100000 Then ActiveCell = 0
                If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) > 500000 Then ActiveCell = 400
                ElseIf (((Range("EnviroBondAmountGrandTotal").ActiveCell.Offset(-2, 0) / 1000) - 1000) * R11C2) Then
        If ActiveCell.Offsett(-2, -2) <> "Original" Then
            If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) < 100000 Then ActiveCell = 0
                If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) > 500000 Then ActiveCell = 0
                ElseIf (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) - (Range("EnviroContractAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) < 100000 Then ActiveCell = 0
                If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) > 500000 Then ActiveCell = 400
                ElseIf (((Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) / 1000) - 1000) * R11C2) Then
    End If
    End If
    End If
ActiveCell.Offset(1, 0).Range("A1").Select

'NEXT 2,000,000 (2000)
ActiveCell.Select
    If EnviroCalculate_Premium_Using_Bond_Amount = "Y" Then
        If ActiveCell.Offset(-3, -2) <> "Original" Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 500000 Then ActiveCell = 0
                If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) > 2000000 Then ActiveCell = 0
                ElseIf ((Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) - Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 500000 Then ActiveCell = 0
                If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) > 2000000 Then ActiveCell = 2000
                ElseIf (((Range("EnviroBondAmountGrandTotal").ActiveCell.Offset(-2, 0) / 1000) - 1000) * R11C2) Then
        If ActiveCell.Offsett(-3, -2) <> "Original" Then
            If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) < 500000 Then ActiveCell = 0
                If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) > 2000000 Then ActiveCell = 0
                ElseIf (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) - (Range("EnviroContractAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) < 500000 Then ActiveCell = 0
                If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) > 2000000 Then ActiveCell = 2000
                ElseIf (((Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) / 1000) - 1000) * R11C2) Then
    End If
    End If
    End If
ActiveCell.Offset(1, 0).Range("A1").Select
'NEXT 2,500,000 (2500)
ActiveCell.Select
    If EnviroCalculate_Premium_Using_Bond_Amount = "Y" Then
        If ActiveCell.Offset(-3, -2) <> "Original" Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 2000000 Then ActiveCell = 0
                If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) > 5000000 Then ActiveCell = 0
                ElseIf ((Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) - Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 2000000 Then ActiveCell = 0
                If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) > 5000000 Then ActiveCell = 2000
                ElseIf (((Range("EnviroBondAmountGrandTotal").ActiveCell.Offset(-2, 0) / 1000) - 1000) * R11C2) Then
        If ActiveCell.Offsett(-3, -2) <> "Original" Then
            If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) < 2000000 Then ActiveCell = 0
                If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) > 5000000 Then ActiveCell = 0
                ElseIf (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) - (Range("EnviroContractAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) < 2000000 Then ActiveCell = 0
                If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) > 5000000 Then ActiveCell = 2000
                ElseIf (((Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) / 1000) - 1000) * R11C2) Then
    End If
    End If
    End If
ActiveCell.Offset(1, 0).Range("A1").Select
'NEXT 2,500,000 (2500)
ActiveCell.Select
    If EnviroCalculate_Premium_Using_Bond_Amount = "Y" Then
        If ActiveCell.Offset(-3, -2) <> "Original" Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 5000000 Then ActiveCell = 0
                If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) > 7500000 Then ActiveCell = 0
                ElseIf ((Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) - Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 5000000 Then ActiveCell = 0
                If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) > 7500000 Then ActiveCell = 2000
                ElseIf (((Range("EnviroBondAmountGrandTotal").ActiveCell.Offset(-2, 0) / 1000) - 1000) * R11C2) Then
        If ActiveCell.Offsett(-3, -2) <> "Original" Then
            If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) < 5000000 Then ActiveCell = 0
                If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) > 7500000 Then ActiveCell = 0
                ElseIf (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) - (Range("EnviroContractAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) < 5000000 Then ActiveCell = 0
                If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) > 7500000 Then ActiveCell = 2000
                ElseIf (((Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) / 1000) - 1000) * R11C2) Then
    End If
    End If
    End If
ActiveCell.Offset(1, 0).Range("A1").Select

'OVER 7,500,000 (7500)
ActiveCell.Select
    If EnviroCalculate_Premium_Using_Bond_Amount = "Y" Then
        If ActiveCell.Offset(-3, -2) <> "Original" Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 7500000 Then ActiveCell = 0
                If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) > 7500000 Then ActiveCell = 0
                ElseIf ((Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) - Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) < 2000000 Then ActiveCell = 0
                If (Range("EnviroBondAmountGrandTotal").Select.ActiveCell.Offset(-2, 0) * R11C2) > 5000000 Then ActiveCell = 2000
                ElseIf (((Range("EnviroBondAmountGrandTotal").ActiveCell.Offset(-2, 0) / 1000) - 1000) * R11C2) Then
        If ActiveCell.Offsett(-3, -2) <> "Original" Then
            If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) < 7500000 Then ActiveCell = 0
                If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) > 7500000 Then ActiveCell = 0
                ElseIf (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) - (Range("EnviroContractAmountGrandTotal").Select.ActiveCell.Offset(-3, 0)) / 1000) * R11C2 Then
            If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) < 7500000 Then ActiveCell = 0
                If (Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) * R11C2) > 7500000 Then ActiveCell = 2000
                ElseIf (((Range("EnviroContractAmountGrandTotal").ActiveCell.Offset(-2, 0) / 1000) - 1000) * R11C2) Then
    End If
    End If
    End If
ActiveCell.Offset(1, 0).Range("A1").Select

何をしても、アクティブ セルに値を返すことができません。前の行からコピーされた数式はそのままで、正しい数式を取得できないようです。

ヘルプ!!!!お願いします!!!!

これは私が今までに書いた最初のマクロです。私は自分自身を教えようとしていますが、障害に次ぐ障害に遭遇しています。

乾杯、キム

4

2 に答える 2

0

これで始められるはずです。ActiveCellを選択/使用する必要はありません。実行している計算は、例からは特に明確ではありません。Selectステートメントを修正し、さらにいくつかの変数を追加する必要があります。

Sub Test()

Dim iRow As Integer, getrows As Integer
Dim rngGrandTotal As Range, rngCalculateBy As Range
Dim lngMultiplier As Long
Dim lngBondResult As Long, lngResult2 As Long
Dim blnCalcUsingBond As Boolean, blnOrig As Boolean

'###Set range "EnviroBerkley_Grand_Total" to a variable and use a with statement to simplify:
Set rngGrandTotal = Range("EnviroBerkley_Grand_Total")
 'ENVIRONMENTAL - RIDER BERKLEY SURETY GROUP PREMIUM
    With rngGrandTotal
        '->>>>>>>>>>> InsertRows ---- >>>>>>>>>>>>>
        iRow = .Row
        getrows = 7
        i = iRow - 1 'first row for insertion
        Rows(i & ":" & i + getrows - 1).Insert
        '<<<<<<<<END Insert Rows----------<<<<<<<<<<
        Offset(-15, 0).Rows("1:7").EntireRow.Copy
        .Offset(7, 0).Range("A1").Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        .Value = "Rider"
        .Offset(-7, 2).Range("A1").Select
    End With

'###Set Multiplier  to R11C2
Set lngMultiplier = Cells(11, 2).Value

'###Set boolean value = I guess if you don't calculate using bond, you calculate using contract?
blnCalcUsingBond = False 'Set to False as default
If EnviroCalculate_Premium_Using_Bond_Amount = "Y" Then blnCalcUsingBond = True

'###See if 'Original' - not sure where you're using this
If rngGrandTotal.Offset(-1, -2).Value = "Original" Then blnOrig = True

'###Set whichever range you're calculating by to a range variable
If blnCalcUsingBond = True Then
    Set rngCalculateBy = Range("EnviroBondAmountGrandTotal")
Else
    Set rngCalculateBy = Range("EnviroContractAmountGrandTotal")
End If



    '###Calculate lngResult (which is rngCalculateBy.Offset(-2,0) * R11C2)
    lngResult = rngCalculateBy.Offset(-2, 0).Value * lngMultiplier
    '###Calculate lngResult2 (which is rngCalculateBy.Offset(-3,0) * R11C2)
    lngResult2 = rngCalculateBy.Offset(-3, 0).Value * lngMultiplier

    '###You now have the 2 numbers that you're calculating with.
    'Looks like you now need to do more calculations (I can't work out what they are from your example)
    'Define more long variables at the top of the Sub and calculate now e.g.
        'Dim lngDifference as Long
        'lngDifference = ((lngresult - lngResult2) / 1000) * lngMultiplier
    '###When all calculations are done, use a select statement to go through the results and set rngGrandTotal to a value
    Select Case lngResult
        Case Is < 100000
            rngGrandTotal.Value = "100"
        Case 100000 To 399999
            rngGrandTotal.Value = "400"
        Case 400000 To 1999999
            rngGrandTotal.Value = "2000"
        '###Etc... you can do Case is >= 7500000
        '###You can also nest If statements in the Case statements if needed
    End Select

End Sub
于 2013-02-12T10:00:07.373 に答える
0

作業コード:

Dim rngCalculateBy As Range
Dim rngContractGrandTotal As Range
Dim rngBondGrandTotal As Range
Dim rngBerkleyGrandTotal As Range
Dim rngWorkTimeCal As Range
Dim rngContractInThousand As Range
Dim rngEnviroCalculate_Premium_Using_Bond_Amount As Range
Dim lngMultiplier As Long
Dim blnCalcUsingBond As Boolean, blnOrig As Boolean

'SETS THE CALCULATIONS
Set rngContractGrandTotal = Range("EnviroContractAmountGrandTotal")
Set rngBondGrandTotal = Range("EnviroBondAmountGrandTotal")
Set rngBerkleyGrandTotal = Range("EnviroBerkley_Grand_Total")
Set rngWorkTimeCal = Range("EnviroWorkTimeCalculation")
Set rngContractInThousand = Range("EnviroContractAmountInThousands")
Set rngMultiplier = Range("EnviroClientPercofParticipation")
Set rngEnviroCalculate_Premium_Using_Bond_Amount = Range("EnviroCalculate_Premium_Using_Bond_Amount")
'BOOLEAN - CALCULATE USING BOND AMOUNT IFEnviroCalculate_Premium_Using_Bond_Amount = "Y"
If Range("EnviroCalculate_Premium_Using_Bond_Amount").Value = "Y" Then
blnCalcUsingBond = True
Else
blnCalcUsingBond = False 'This sets to False as default
End If

'BOOLEAN - CALCULATE USING ORGINAL FORMULAS OR RIDER FORMULAS
blnOrig = False
If Range("EnviroBerkley_Grand_Total").Offset(-8, 0).Value = "Original" Then
blnOrig = True
End If

'IF STATEMENT - SETS THE RANGE TO CALCULATE OFF EITHER BOND AMOUNT OR CONTRACT AMOUNT
If blnCalcUsingBond = True Then
    Set rngCalculateBy = rngBondGrandTotal
Else
    Set rngCalculateBy = rngContractGrandTotal
End If

Dim lngDifference As Long
Dim lngDifference2 As Long
Dim lngResult As Long
Dim lngResult2 As Long

'SETS THE CALCULATIONS
    lngResult = rngCalculateBy.Offset(-2, 0).Value
    lngResult2 = rngCalculateBy.Offset(-3, 0).Value 'SETS lngResult2
    lngDifference = lngResult * rngMultiplier
    lngDifference2 = ((lngResult - lngResult2) / 1000)

'CELL 1 - FIRST 100,000 (100)
Range("EnviroContractAmountInThousands").Select
ActiveCell.Offset(-7, 0).Range("A1").Select
If blnCalcUsingBond = True And blnOrig = False Then
    ElseIf lngDifference > 100000 Then ActiveCell = 0
       Else: ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
If blnCalcUsingBond = False And blnOrig = False Then
    ElseIf lngDifference > 100000 Then ActiveCell = 0
       Else: ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
ActiveCell.Offset(1, 0).Range("A1").Select
'CELL 2 - NEXT 400,000 (400)
If blnCalcUsingBond = True And blnOrig = False Then
        ElseIf lngDifference < 100000 Then ActiveCell = 0
        ElseIf lngDifference > 500000 Then ActiveCell = 0
                Else: ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
If blnCalcUsingBond = False And blnOrig = False Then
        ElseIf lngDifference < 100000 And lngDifference > 500000 Then ActiveCell = 0
                Else: ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
ActiveCell.Offset(1, 0).Range("A1").Select
'CELL 3 - NEXT 2,000,000 (2000)
If blnCalcUsingBond = True And blnOrig = False Then
        ElseIf lngDifference < 500000 Then ActiveCell = 0
        ElseIf lngDifference > 2000000 Then ActiveCell = 0
                Else: ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
If blnCalcUsingBond = False And blnOrig = False Then
        ElseIf lngDifference < 500000 Then ActiveCell = 0
        ElseIf lngDifference > 2000000 Then ActiveCell = 0
                Else: ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
ActiveCell.Offset(1, 0).Range("A1").Select
'CELL 4 - NEXT 2,500,000 (2500)
If blnCalcUsingBond = True And blnOrig = False Then
        ElseIf lngDifference < 2000000 Then ActiveCell = 0
        ElseIf lngDifference > 5000000 Then ActiveCell = 0
                Else: ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
If blnCalcUsingBond = False And blnOrig = False Then
        ElseIf lngDifference < 2000000 Then ActiveCell = 0
        ElseIf lngDifference > 5000000 Then ActiveCell = 0
                Else: ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
ActiveCell.Offset(1, 0).Range("A1").Select
'CELL 5 - NEXT 2,500,000 (2500)
If blnCalcUsingBond = True And blnOrig = False Then
        ElseIf lngDifference < 5000000 Then ActiveCell = 0
        ElseIf lngDifference > 7500000 Then ActiveCell = 0
                Else: ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
If blnCalcUsingBond = False And blnOrig = False Then
        ElseIf lngDifference < 5000000 Then ActiveCell = 0
        ElseIf lngDifference > 7500000 Then ActiveCell = 0
                Else: ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
ActiveCell.Offset(1, 0).Range("A1").Select
'CELL 6 - OVER 7,500,000 (7500)
If blnCalcUsingBond = True And blnOrig = False Then
        ElseIf lngDifference < 7500000 Then ActiveCell = 0
        ElseIf lngDifference > 7500000 Then ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
If blnCalcUsingBond = False And blnOrig = False Then
        ElseIf lngDifference < 7500000 Then ActiveCell = 0
        ElseIf lngDifference > 7500000 Then ActiveCell.Formula = lngDifference2 * rngMultiplier
End If
ActiveCell.Offset(1, 0).Range("A1").Select
于 2013-03-08T20:34:59.447 に答える