Results 1 to 7 of 7

Thread: Solved: 2 formulas required - Part 1

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location

    Solved: 2 formulas required - Part 1

    Hi,

    I have a spreadsheet where there is a macro button that once clicked submits all the information to a spreadsheet/database.

    What I am looking for is something to add into the code that will pop up an error message box if the conditions are not met.

    The conditions are: If A1 is complete then B1 cannot be, if B1 is complete then A1 cannot be, If neither A1 or B1 is completed then show error too.

    The second one I need help with is a working days scenario on a completely different spreadsheet, so I am going to post it on a completely different thread.

    Cheers

    Hoopsah
    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    [vba]
    If Range("A1").Value = "" OR Range("B1").VAlue = "" Then

    MsgBox "Error"
    Else

    '... do your stuff
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location
    Hi XLD,

    thanks for that, I hadn't even got question 2 written.

    This formula works if both cells are blank, but what I actually want is the user must input details into at least one cell.

    Sorry for not being clear.
    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    No it tests OR not AND.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location
    Hi again,

    it is an OR but when I input into only one of the cells I get an error. I need to be able to input into one and not the other.

    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    Sorry, is this what you want?

    [vba]

    If (Range("A1").Value = "" And Range("B1").Value = "") Or _
    (Range("A1").Value <> "" And Range("B1").Value <> "") Then

    MsgBox "Error"
    Else

    '... do your stuff
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location
    Man!

    That is exactly it, works perfectly.

    Thanks a lot for your time on these 2 problems today XLD



    Hoopsah
    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •