Hello everyone!
I have a nested IF statement that works perfectly if put directly into the cell on the spreadsheet side, but cannot get it to work if I try to use it as VBA Code instead.
The set up I am using is based on a series of "Yes" "No" selections:
<= 8 "Yes" = Pink Elephants "on Parade"
> 8 And < 13 "Yes" = Pink Elephants "on Vacay"
Else (anything greater than 13) = Pink Elephants "sound asleep"
Here is the nested IF statement that is directly put into the cell:
=IF(C21<=8,"on Parade",IF(AND(C21>8,C21<13),"on Vacay","sound asleep"))
As mentioned before, it works as should if entered directly into the cell. But when coding the same in VBA:
Sub PinkElephants()
If Cells(21, 2) <= 8 Then
Cells(23, 2) = "on Parade"
ElseIf Cells(21, 2) > 8 And Cells(21, 2) < 13 Then
Cells(23, 2) = "on Vacay"
Else
Cells(23, 2) = "sound asleep"
End If
End Sub
The cell will only display Pink Elephants "on Parade", and does not change even once the number of "Yes" selections are 9 or greater. Any idea why it is not working?
I have attached two spread sheets to detail both scenarios (one using only the nested IF statement directly in the cell, and the other spreadsheet only using VBA code).
Bookmarks