jeudi 13 décembre 2018

IF else statement not working properly in vba code

Hi please see the following code im trying to print volume and the package size based on volume using if else in vba. but my code only works fine for the volume part but when it comes to the size it is printing the first condition throughout i.e small not printing the rest. can you help me to see where am i going wrong. the table has the following coulmns with values in multiple rows: package name, date, length, width, height, volume, size.

works fine for volume but not sizeenter image description here

Sub FillDown()

Dim strFormulas(1 To 2) As Variant

With ThisWorkbook.Sheets("Sheet1")
    strFormulas(1) = "=PRODUCT(C2:E2)"

    If Range("F2").Value > 0 And Range("F2").Value < 1000000 Then
        strFormulas(2) = "Small"

    ElseIf Range("F2").Value > 1000000 And Range("F2").Value < 9000000 Then
        strFormulas(2) = "Medium"

    ElseIf Range("F2").Value > 9000000 Then
        strFormulas(2) = "Large"

    End If
    .Range("F2:G2").Formula = strFormulas
    .Range("F2:G44").FillDown
End With

End Sub

Aucun commentaire:

Enregistrer un commentaire