+ Reply to Thread
Results 1 to 6 of 6

IsEmpty Help for multiple Cells

Hybrid View

  1. #1
    Registered User
    Join Date
    02-04-2019
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    41

    IsEmpty Help for multiple Cells

    Hi,

    In the spreadsheet I am working on, I have 2 different sets of Contacts:

    Contact 1 = cells E55 (Con1) and E59 (Con2)
    Contact 2 = cells E77 (Con3) and E81 (Con4)

    I have code so that if all the cells are blank, then a MsgBox will pop up (thanks to ArkAdi for the assistance )

    However, I need to expand this so if one of the 2 cells in each contact group (e.g. Contact 1 or Contact 2) is blank that a MsgBox will pop up giving a warning. (e.g. If Con1 <> 0, but Con2 = 0 & Con3 and Con4 =0 - MsgBox stating that Con2 is Blank)

    The following code will warn if all cells are blank, but then also runs the individual cell check. Or if one of the cells isnt blank, then it will run the IsEmpty code only.

    Sub Contact_2()
    Dim Con1, Con2, Con3, Con4
    Dim str As String
    
    Con1 = Worksheets("Registration Form").Range("E55").Value
    Con2 = Worksheets("Registration Form").Range("E59").Value
    Con3 = Worksheets("Registration Form").Range("E77").Value
    Con4 = Worksheets("Registration Form").Range("E81").Value
    
    If WorksheetFunction.CountA(Range("E55,E59,E77,E81")) = 0 Then
        MsgBox "this is a test"
    Else
    GoTo Contst:
    
    End If
    
    Contst:
    Con1 = Worksheets("Registration Form").Range("E55").Value
        If IsEmpty(Con1) Then
            str = "Please input the required Con1" & vbCrLf
        End If
    Con2 = Worksheets("Registration Form").Range("E59").Value
        If IsEmpty(Con2) Then
            str = str + "Please input the required Con2" & vbCrLf
        End If
    Con3 = Worksheets("Registration Form").Range("E77").Value
        If IsEmpty(Con3) Then
            str = str + "Please input the required Con3" & vbCrLf
        End If
    Con4 = Worksheets("Registration Form").Range("E81").Value
        If IsEmpty(Con4) Then
            str = str + "Please input the required Con4" & vbCrLf
        End If
    
    If Len(str) > 0 Then
      MsgBox str & " " & vbCrLf & "Once completed, submit your request again"
    End If
    
    Exit Sub
    Hopefully I have explained what I need clearly enough and thank you in advance,

    Chris

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: IsEmpty Help for multiple Cells

    Hello ChrisMP,

    This Worked for me...
    Sub Contact_2()
    
        Dim Con1 As Range
        Dim Con2 As Range
        Dim Con3 As Range
        Dim Con4 As Range
        Dim Msg  As String
        
            With Worksheets("Registration Form")
                Set Con1 = .Range("E53")
                Set Con2 = .Range("E59")
                Set Con3 = .Range("E77")
                Set Con4 = .Range("E81")
            End With
            
            If Application.CountA(Con1, Con2, Con3, Con4) = 0 Then
                MsgBox "Please fill in all required fields"
                Exit Sub
            End If
        
            If IsEmpty(Con1) Xor IsEmpty(Con2) Then
                If IsEmpty(Con1) Then
                    Msg = Msg & "Please input the required Con1" & vbLf
                Else
                    Msg = Msg & "Please input the required Con2" & vbLf
                End If
            End If
        
            If IsEmpty(Con3) Xor IsEmpty(Con4) Then
                If IsEmpty(Con3) Then
                    Msg = Msg & "Please input the required Con3" & vbLf
                Else
                    Msg = Msg & "Please input the required Con4" & vbLf
                End If
            End If
        
        If Msg <> "" Then MsgBox Msg
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    02-04-2019
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    41

    Re: IsEmpty Help for multiple Cells

    Hi Leigh Ross,

    Thank you very much for the code, works a treat. Plus I learned about Xor....

    Chris

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: IsEmpty Help for multiple Cells

    Try
    Sub Contact_2()
        Dim i As Long, msg As String, x As Range
        With Sheets("Registration Form")
            With .Range("e55,e59,e77,e81")
                For i = 1 To .Areas.Count
                    If IsEmpty(.Areas(i).Value) Then msg = msg & ", Con" & i
                Next
            End With
        End With
        If Len(msg) Then MsgBox "Please input the required" & _
                String(2, vbLf) & Mid$(msg, 3), vbCritical
    End Sub

  5. #5
    Registered User
    Join Date
    02-04-2019
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    41

    Re: IsEmpty Help for multiple Cells

    Hi jindon,

    Thank you very much for the simplified code - bit beyond my comprehension at the moment but hope to get to that level

    Chris

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: IsEmpty Help for multiple Cells

    You are welcome and thanks for the rep.

    Is is a very simple code so I hope you will understand easily.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] IsEmpty for multiple cells
    By Maleficent in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-29-2019, 08:23 AM
  2. [SOLVED] Do While IsEmpty Help
    By DavidWally in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2019, 10:41 PM
  3. Replies: 1
    Last Post: 10-30-2018, 05:01 AM
  4. Copy all cells in range if not isempty
    By rynofrowan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2013, 06:15 AM
  5. Isempty with cells
    By katto01 in forum Excel General
    Replies: 2
    Last Post: 02-08-2012, 03:03 AM
  6. IsEmpty
    By Determined in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-05-2007, 07:44 PM
  7. [SOLVED] IsEmpty() Returns False in empty cells
    By John Hutchins in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-29-2005, 10:07 PM

Tags for this Thread

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.6.0 RC 1