+ Reply to Thread
Results 1 to 6 of 6

Thread: IF cell A = Y and cell B = "" THEN = messagebox

  1. #1
    Registered User
    Join Date
    12-20-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    14

    IF cell A = Y and cell B = "" THEN = messagebox

    Hi,

    This is a really simple one but I can't get it to work:

    I have a dropdown list with Yes or No in cell M14.

    I need the VBA code for:

    When M14 = Yes and M16 = "" (empty)
    for a message box to appear with "Please state the Filename"

    Many thanks
    Last edited by jammy78; 01-27-2012 at 04:50 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: IF cell A = Y and cell B = "" THEN = messagebox

    try this way ... type below code in your sheet's code
    Private Sub Worksheet_Change(ByVal Target As Range)
     if target.address = "$M$14" or target.address = "$m$16" then
       if range("m14").value = "Yes" and range("m16").value = "" then MsgBox "test message"
     end if
    End Sub
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to use the Scales icon to rate it - This way you will add me some reputation points ... thanks in advance.

  3. #3
    Registered User
    Join Date
    12-20-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: IF cell A = Y and cell B = "" THEN = messagebox

    Sorry, I should have probably said - I want to add the code to an existing command.

    This is some of the code in the command:

    Sub AddDesk_Click()
    If Range("D4").Value = "" Then
                MsgBox ("Please insert Project Name")
                Exit Sub
            End If
        If Range("D6").Value = "" Then
                MsgBox ("Please insert Contact Name")
                Exit Sub
            End If
        If Range("D8").Value = "" Then
                MsgBox ("Please insert Pay or Warrant Number")
                Exit Sub
            End If
        If Range("D10").Value = "" Then
                MsgBox ("Please insert a Tel Number")
                Exit Sub
            End If
    So I need to add it to this!

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: IF cell A = Y and cell B = "" THEN = messagebox

    see the code provided by maczaq and change it for yr needs
    as an option
    Sub Button2_Click()
    If Range("m14").Value = "Yes" And Range("m16").Value = "" Then MsgBox "Please insert a Tel Number"
    End Sub
    Regards, John

  5. #5
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: IF cell A = Y and cell B = "" THEN = messagebox

    nothing more to say that john55 wrote

    maybe shorter code ?
    Sub AddDesk_Click()
      If Range("D4").Value = "" Then MsgBox ("Please insert Project Name"): Exit Sub
      If Range("D6").Value = "" Then MsgBox ("Please insert Contact Name"): Exit Sub
      If Range("D8").Value = "" Then MsgBox ("Please insert Pay or Warrant Number"): Exit Sub
      If Range("D10").Value = "" Then MsgBox ("Please insert a Tel Number"): Exit Sub
      If Range("m14").Value = "Yes" And Range("m16").Value = "" Then MsgBox "Please insert a Tel Number"
    End Sub
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to use the Scales icon to rate it - This way you will add me some reputation points ... thanks in advance.

  6. #6
    Registered User
    Join Date
    12-20-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: IF cell A = Y and cell B = "" THEN = messagebox

    Quote Originally Posted by maczaq View Post
    nothing more to say that john55 wrote

    maybe shorter code ?
    Sub AddDesk_Click()
      If Range("D4").Value = "" Then MsgBox ("Please insert Project Name"): Exit Sub
      If Range("D6").Value = "" Then MsgBox ("Please insert Contact Name"): Exit Sub
      If Range("D8").Value = "" Then MsgBox ("Please insert Pay or Warrant Number"): Exit Sub
      If Range("D10").Value = "" Then MsgBox ("Please insert a Tel Number"): Exit Sub
      If Range("m14").Value = "Yes" And Range("m16").Value = "" Then MsgBox "Please insert a Tel Number"
    End Sub
    What a fool..... I forgot to put the " " round the yes, when I tried! It was a long day.......... ?

    Many thanks for the help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0