How do I implement if-else functionalilty for a cell in excel?

G

Guest

I want to have two cells with one cell depending on the other value. Ex. If
A1=Raja then A2 should display 11, else if A1=Chirala, then A2 should display
12.

Please give information on this if this type of programming is possible in
excel.
 
A

acampbell012

In A2, =if(a1="Raja",11,if(a1="Chirala",12,""))

A2 will display blank if neither condition is met.
 
G

Gary Keramidas

you could use select case

Sub test()
Dim nm As String
nm = Range("A1").Value
Select Case nm
Case "raja"
Range("a2").Value = 11
Case "Chirala"
Range("A2").Value = 12
Case Else
Range("a2").Value = ""

End Select
End Sub
 
G

Guest

Here is the If ...Then...ElseIf code:

Sub RajChi()
If Range("$A$1").Value = "Raja" Then
Range("$A$2").Value = "11"
ElseIf Range("$A$1").Value = "Chirala" Then
Range("$A$2").Value = "12"
End If
End Sub

This works on a pass basis. That is, if a name is in the cell when the code
runs you will get the appropriate number. However, if you change the name
and don't run the code again, the number does not change.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top