+ Reply to Thread
Results 1 to 5 of 5

IsEmpty for multiple cells

Hybrid View

Maleficent IsEmpty for multiple cells 04-29-2019, 06:36 AM
romperstomper Re: IsEmpty for multiple cells 04-29-2019, 06:44 AM
Maleficent Re: IsEmpty for multiple cells 04-29-2019, 08:02 AM
romperstomper Re: IsEmpty for multiple cells 04-29-2019, 08:11 AM
Maleficent Re: IsEmpty for multiple cells 04-29-2019, 08:23 AM
  1. #1
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    IsEmpty for multiple cells

    Hi,

    I'm creating a form which users will complete and email. I need certain mandatory fields to be completed.

    I have code which checks if a cell is empty, if it is it prompts a message box and turns the corresponding question cell red. if it is not blank, it will create a pdf and send an email.

    This is working however I have several mandatory cells and I'm not sure the best way to write the code to test all mandatory cells before moving on to send the email. if any of them is blank I want to flag the message box and turn any/all blank questions red.

    Here is what I have so far:
    Sub RDB_Worksheet_Or_Worksheets_To_PDF_And_Create_Mail()
    
    
    If IsEmpty(Range("B2").Value) = True Then
        MsgBox "Please Complete Mandatory Fields"
        Range("A2").Font.ColorIndex = 3
        Else
    
        Dim FileName As String
    
        If ActiveWindow.SelectedSheets.Count > 1 Then
            MsgBox "There is more then one sheet selected," & vbNewLine & _
                   "be aware that every selected sheet will be published"
        End If
    
        'Call the function with the correct arguments
        'Tip: You can also use Sheets("YourSheetName") instead of ActiveSheet in the code(sheet not have to be active then)
    
        FileName = RDB_Create_PDF(Source:=ActiveSheet, _
                                  FixedFilePathName:="", _
                                  OverwriteIfFileExist:=True, _
                                  OpenPDFAfterPublish:=False)
    
        'For a fixed file name use this in the FixedFilePathName argument
        'FixedFilePathName:="C:\Users\Ron\Test\YourPdfFile.pdf"
    
    
        If FileName <> "" Then
            RDB_Mail_PDF_Outlook FileNamePDF:=FileName, _
                                 StrTo:="CorporateInsuranceMotorNewClaims@nfumutual.co.uk", _
                                 StrCC:="", _
                                 StrBCC:="", _
                                 StrSubject:="New Claim Notification", _
                                 Signature:=True, _
                                 Send:=False, _
                                 StrBody:="<H3><B>Please find attached new claim notification</B></H3><br>"
        Else
            MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
                   "Microsoft Add-in is not installed" & vbNewLine & _
                   "You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
                   "The path to Save the file in arg 2 is not correct" & vbNewLine & _
                   "You didn't want to overwrite the existing PDF if it exist"
        End If
    End If
    
    End Sub

    Many thanks in advance!

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: IsEmpty for multiple cells

    You can do something like this:

    Dim cell as range
    for each cell in Range("B2,C3,D4,E5").Cells
      If IsEmpty(cell.Value) = True Then
        dim Incomplete as Boolean
        Incomplete = True
        cell.Font.ColorIndex = 3
        end if
    next cell
    If Incomplete then
    MsgBox "Please Complete Mandatory Fields"
    else
    ' rest of code
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: IsEmpty for multiple cells

    Brilliant! second time you've sorted me out today Rory!

    Only thing is, its not the empty cell I want to turn red but the adjacent cell. eg. if B3 is blank, make A3 red?

    Thanks again!

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: IsEmpty for multiple cells

    Then refer to cell.offset(, -1)

  5. #5
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: IsEmpty for multiple cells

    Rorya you're a legend, thank you so much!

+ 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] Do While IsEmpty Help
    By DavidWally in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2019, 10:41 PM
  2. Replies: 1
    Last Post: 10-30-2018, 05:01 AM
  3. 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
  4. Not isempty()
    By nikko50 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-08-2013, 01:19 PM
  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. 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

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