Using If-Then Function in VBA

[Closed]
Report
-
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
-
Hello,

I wanted to make a macro so when column C has a certain number in a row then in column E, with the same row, it will insert a name. Ex. When 4242 shows up in column C then column E with the same row will should have the word Jeff. Does anyone know how to do this in Excel vba for multiple If-Then statements or whatever is the most efficient method. P.S. I just started using vba so I dont know a lot. Thanks a lot in advance.

1 reply

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
768
If there are many if -elseif....else..end if. then you are better off using Select Case .. Case ... End Select


like
    lRow = 1
    
    Select Case Range("C" & lRow)
        Case Is = 5
            Range("e" & lRow) = "A"
    
        Case Is = 6
            Range("E" & lRow) = "t"
        
        Case Is = 6
            Range("E" & lRow) = 8
        
        Case Else
            Range("E" & lRow) = ""
    
    End Select