Home Invalid Outside Procedure error with VBA
Reply: 1

Invalid Outside Procedure error with VBA

F Kawalski
1#
F Kawalski Published in 2017-12-07 19:26:26Z

I am trying to combine several cells of data with the same label. There will either be 2 or 3 (also accounted for 1) repeated cells. I keep getting an invalid outside procedure error function. It highlights the "module module1" so I think it is something to do with defining my class, but I am not familar enough with VBA to figure it out.

Module Module1
Public Sub Main()
    Dim num As Integer
    num = 2
    Dim val As Integer
    val = 2
    While num <= 5031
        If StrComp(Cells(num, 3).Value, Cells((num + 1), 3).Value, vbTextCompare) = 0 And StrComp(Cells(num, 3).Value, Cells((num + 1), 3).Value, vbTextCompare) = 0 Then
            Cells(val, 5) = Calls(num, 3).Value
            Cells(val, 6) = Add(Cells(num, 4).Value, Cells(num + 1, 4).Value, Cells(num + 2, 4).Value)
            num = num + 3
            val = val + 1
            End If
        ElseIf StrComp(Cells(num, 3).Value, Cells((num + 1), 3).Value, vbTextCompare) = 0 Then
            Cells(val, 5) = Calls(num, 3).Value
            Cells(val, 6) = Add(Cells(num, 4).Value, Cells(num + 1, 4).Value)
            num = num + 2
            val = val + 1
            End If
        Else
            Cells(val, 5) = Calls(num, 3).Value
            Cells(val, 6) = Cells(num, 4).Value
            num = num + 1
            val = val + 1
            End If

    Wend
End Sub
Jamie Riis
2#
Jamie Riis Reply to 2017-12-08 02:58:23Z

Delete the extra End If statements. VBA If ... Then ... Else format is as follows:

If choice Then
    Statements...
ElseIf nextChoice Then
    Statements...
...as Many Elseif's as you need
Else
    Statements...
End If

I believe that the VBA compiler is unable to recover from the extra End If statements

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.330085 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO