Josh McKearin
Josh McKearin

Reputation: 742

Excel VBA "End If without block If" - VBA error

I can not figure out why VBA is yelling at me on this one. Very simple code, only one if statement is involved, and it clearly has a "Starting" If and a matching End If. I am a VB.NET developer, so it may be a difference in the syntax that I am missing.

 Sub splitter()
   Dim line() As String
   Dim rng As Range
   Dim row As Range
   Dim cell As Range
      For Each row In rng.Rows
        If row.Value <> "" Then
            line = Split(Range(row, 1), ",")
            Select Case line(0)
               Case "Desktop"
                   Range(row, 8).Value = "Desktop"
               Case "Laptop"
                   Range(row, 8).Value = "Laptop"
               Case "Server"
                   Range(row, 8).Value = "Server"
               Case Else
                   Range(row, 8).Value = "N/A"
        End If
       Next
    End Sub

Specifically, the end result is that it will populate a "Child" drop down list (Range(row, 8)) based on the selection made from of the "Parent" drop down list (Range(row, 1)). Because the question will arise, the reason I am doing this using VBA is because I can utilize the Split() function with the way the items in the Parent drop down list are made eg. "Desktop, Dell, 745". Also, I am a better programmer than an excel developer.

Upvotes: 2

Views: 6813

Answers (1)

Jon Crowell
Jon Crowell

Reputation: 22338

Your select statement needs an end:

Select Case line(0)
   Case "Desktop"
       Range(row, 8).Value = "Desktop"
   Case "Laptop"
       Range(row, 8).Value = "Laptop"
   Case "Server"
       Range(row, 8).Value = "Server"
   Case Else
       Range(row, 8).Value = "N/A"
End Select

Upvotes: 8

Related Questions