2

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.

1 Answer 1

8

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you sir! Will vote up as answer. However, with that change, I am getting Runtime Error '91': Object variable or With block variable not set. Do all of my Dim'd variables have to be set to something (or "Nothing")?
Never mind I see the problem. I need to set my rng Range. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.