Results 1 to 2 of 2

Thread: Else if error in VBA

  1. #1

    Else if error in VBA



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hello! I'm a total beginner at VBA and tried to do the nested if function but after typing ElseIf, there's a msg box saying
    "Compiled Error:
    Expected: Expression"

    This is what I did so far:

    Sub ifs()

    If Worksheets("Control").Cells(38, 15) = Cells(32, 15) And Cells(35, 5) = Cells(32, 5) Then
    Worksheets("FinancialRatioAnalysis").Cells(47, 1) = Worksheets("Process").Cells(95, 2)
    elseif

    I wanted to do a similar thing like this in VBA but I've totally got no idea how to start on it. Can anyone help? Thanks a lot!
    The final worksheet is called "FinancialRatioAnalysis"

    =IF(AND(Control!$O$38=Control!$O$32,Control!$E$35=Control!$E$32),Process!$B$95,IF(AND(Control!$O$38=Control!$O$32,Contro l!$E$35=Control!$E$33),Process!$B$96,IF(AND(Control!$O$38=Control!$O$33,Control!$E$35=Control!$E$32),Process!$B$100,IF(A ND(Control!$O$38=Control!$O$33,Control!$E$35=Control!$E$33),Process!$B$101,IF(AND(Control!$O$38=Control!$O$34,Control!$E $35=Control!$E$32),Process!$B$105,IF(AND(Control!$O$38=Control!$O$34,Control!$E$35=Control!$E$33),Process!$B$106,IF(AND( Control!$O$38=Control!$O$35,Control!$E$35=Control!$E$32),Process!$B$111,IF(AND(Control!$O$38=Control!$O$35,Control!$E$35 =Control!$E$33),Process!$B$112,IF(AND(Control!$O$38=Control!$O$35,Control!$E$35,Control!$E$33),Process!#REF!,IF(AND(Cont rol!$O$38=Control!$O$36,Control!$E$35=Control!$E$32),Process!$B$116,Process!$B$117))))))))))

  2. #2
    Code:
    Sub ifs()
    
    
        With Worksheets("Control")
        
            If .Range("O38").Value = .Range("O32").Value And .Range("E35").Value = .Range("E32").Value Then
        
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B95").Value
        ElseIf .Range("O38").Value = .Range("O32").Value And .Range("E35").Value = .Range("E33").Value Then
            
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B96").Value
        ElseIf .Range("O38").Value = .Range("O33").Value And .Range("E35").Value = .Range("E32").Value Then
            
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B100").Range("B96").Value
        ElseIf .Range("O38").Value = .Range("O33").Value And .Range("E35").Value = .Range("E33").Value Then
            
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B101").Value
        ElseIf .Range("O38").Value = .Range("O34").Value And .Range("E35").Value = .Range("E32").Value Then
            
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B105").Value
        ElseIf .Range("O38").Value = .Range("O34").Value And .Range("E35").Value = .Range("E33").Value Then
            
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B106").Value
        ElseIf .Range("O38").Value = .Range("O35").Value And .Range("E35").Value = .Range("E32").Value Then
            
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B111").Value
        ElseIf .Range("O38").Value = .Range("O35").Value And .Range("E35").Value = .Range("E33").Value Then
            
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B112").Value
        ElseIf .Range("O38").Value = .Range("O35").Value And .Range("E35").Value = .Range("E33").Value Then
            
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B114").Value
        ElseIf .Range("O38").Value = .Range("O36") And .Range("E35").Value = .Range("E32").Value Then
            
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B116").Value
        Else
        
            Worksheets("FinancialRatioAnalysis").Range("A47").Value = Worksheets("Process").Range("B117").Value
        End
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •