Find the solution to skip blank cell with my VBA code.

maiwarits

New Member
Joined
Jul 17, 2022
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi! guys I'm new with VBA code.
Firstly, My native language is not English so may be it look weird in some word.

I do some alert when the date will approaching deadline by VBA code into outlooks .
And I want to skip all blank cell in the loop to alert only the cell with the date.
But I don't know the code to skip them and where to place them in my code.
Hope , I explain this clearly for you all.

Many Thanks!

Invoic.JPG


VBA Code:
Sub InvoiceAlert()


Set tbl = ActiveSheet.ListObjects("ProjectTable")

        Dim EmailApp As Outlook.Application
        Set EmailApp = New Outlook.Application
        Dim EmailItem As Outlook.MailItem
        Set EmailItem = EmailApp.CreateItem(olMailItem)

'get current date
DateToday = Date

'check number of rows
NumRows = tbl.DataBodyRange.Rows.Count

'set day to noti
NumDayNoti = Range("T2")

    CountPreNoti = 0
    
    For i = 1 To NumRows
    
        projInvoiceDate = tbl.DataBodyRange.Cells(i, tbl.ListColumns("InvoiceDate").Index)
        
        projInvoiceFinish = tbl.DataBodyRange.Cells(i, tbl.ListColumns("InvoiceFinish").Index)
        
    
        If projInvoiceFinish <> "DONE" And (projInvoiceDate - NumDayNoti) <= DateToday Then
        
        PreNotiMsg = PreNotiMsg & GetTableData(i) & "<br>"
        CountPreNoti = CountPreNoti + 1
        
        End If
        
    Next i
    
        If CountPreNoti > 0 Then
        
                'E-mail that need to send and CC.
            EmailItem.To = " e-mail"
            EmailItem.CC = " e-mail"
            
                'E-mail Subject.
            EmailItem.Subject = "Invoice Deadline is approaching soon"
            
                'E-mail body.
            EmailItem.HTMLBody = _
                        "Dear All," & _
                            "<br><br>" & _
                                "follow invoice soon." & _
                            "<br>" & _
                                " __________________________________________________________________________________" & _
                            "<br><br>" & _
                                " INVOICE DATE IS APPROACHING : " & CountPreNoti & " items " & _
                            "<br><br>" & _
                                PreNotiMsg & _
                            "<br><br>" & _
                                "Please check and update the file" & _
                            "<br>" & _
                                dHyperlink & _
                            "<br><br>" & _
                                "This E-mail generated by Excel VBA." & _
                            "<br>" & _
                                "Thank you,"

            EmailItem.Display
           
        End If
            
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi And welcome
Try
VBA Code:
If projInvoiceDate <> "" Then

    If projInvoiceFinish <> "DONE" And (projInvoiceDate - NumDayNoti) <= DateToday Then

        PreNotiMsg = PreNotiMsg & GetTableData(i) & "<br>"
        CountPreNoti = CountPreNoti + 1

    End If
End If
 
Upvote 0
Solution
Hi And welcome
Try
VBA Code:
If projInvoiceDate <> "" Then

    If projInvoiceFinish <> "DONE" And (projInvoiceDate - NumDayNoti) <= DateToday Then

        PreNotiMsg = PreNotiMsg & GetTableData(i) & "<br>"
        CountPreNoti = CountPreNoti + 1

    End If
End If
Dear Mohadin,

This code work with my expected!

Many Thanks!
 
Upvote 0
You are very welcome
And thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,007
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top