Using If-Then Function in VBA

Closed
kook - Jul 9, 2010 at 10:44 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Jul 9, 2010 at 04:54 PM
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.

Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jul 9, 2010 at 04:54 PM
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
0