IF THEN ELSEIF - newbie needs help

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi all

I am trying to learn as I go and desperately hoping someone can help
me...First I will explain what I want the program to do, then I will
paste my code....(which is not working : ))

What I want is this: If Cell A2 contains the value 2, and cell e5 is
null, then cell A15 should contain nothing.

But...if cell a2 contains 2 and cell e5 is greater than 84999 or less
than 12000, cell A15 should display "Error"

This will go on for about 4 or 5 cells (e6, e7, e8, etc.) The first
part of it is ok, I am having trouble with the ElseIf. Everytime I
think I get it (and I have looked at some samples on the web), it is
not right and I can't seem to figure out what I am doing wrong. Would
appreciate anyone helping...I think I should say that I would not ever
consider asking anyone to write code for me...i know the value of that
knowledge...but I am trying to teach myself and just would like some
guidance....Thanks!

This is my code:

Sub Test2()
If Range("a1") = 2 Then
If Range("e5") = "" Then Range("a15") = ""
ElseIf Range("e5") > 849999 Then Range("a15") = "Error"
Else: Range("a15") = ""
End If
ElseIf Range("e5") < 120000 Then Range("a15") = "Error"
Else: Range("a15") = ""
End If
End Sub

.



Relevant Pages

  • Re: Yet more validation ... challenges!
    ... The NI number is validated using data validation, ... hitting delete on a valid postcode does generate the error ... Private Sub Worksheet_Change ... If prev = "" Then ...
    (microsoft.public.excel)
  • Re: Yet more validation ... challenges!
    ... When I close the workbook, whether or not I save it, on opening it again I ... Private Sub Worksheet_Change ... If prev = "" Then ... MsgBox "Invalid postcode, ...
    (microsoft.public.excel)
  • Re: Yet more validation ... challenges!
    ... Private Sub Worksheet_Change(ByVal Target As Range) ... If prev = "" Then ... On Error GoTo EndMacro ...
    (microsoft.public.excel)
  • can you help?
    ... Private Sub Worksheet_Calculate ... If init And v prev Then ... >Private Sub Worksheet_Calculate ...
    (microsoft.public.excel.misc)
  • Re: Need VBA help
    ... ElseIf ... Dim NumIncorrect As Integer ... Sub StartGame() ... ElseIf NumCorrect> 10 Then ...
    (microsoft.public.powerpoint)