Help getting Macro to skip blank cells

VexedVBA

New Member
Joined
Apr 9, 2015
Messages
6
I work for a recruitment firm and as such much of my day is spent calling numerous people. Many of these people are unable to talk at the present time and instruct me to call back days, weeks even months later.

I record all calls etc in an excel spreadsheet and would like to be add call back date and details then run a macro that puts an appointment in my outlook calendar.

I have written the following which works however is unable to skip blank cells (people who I do not need to call back)

Any assistance in fixing the code so I can run it and have it skip the blank cells between entries would be much appreciated.

Sub Outlook()
Sub AddAppointments()
' Create the Outlook session
Set myOutlook = CreateObject("Outlook.Application")


' Start at row 2
r = 2


Do Until Trim(Cells(r, 8).Value) = ""

If Cells(r, 8).Value <> "Done" Then

' Create the AppointmentItem
Set myApt = myOutlook.createitem(1)
' Set the appointment properties
myApt.Subject = Cells(r, 8).Value
myApt.Location = Cells(r, 9).Value
myApt.Start = Cells(r, 10).Value
myApt.Duration = Cells(r, 11).Value
' If Busy Status is not specified, default to 2 (Busy)
If Trim(Cells(r, 12).Value) = "" Then
myApt.BusyStatus = 2
Else
myApt.BusyStatus = Cells(r, 12).Value
End If
If Cells(r, 13).Value > 0 Then
myApt.ReminderSet = True
myApt.ReminderMinutesBeforeStart = Cells(r, 13).Value
Else
myApt.ReminderSet = False
End If
myApt.Body = Cells(r, 14).Value
myApt.Save
Cells(r, 15) = "Done" 'Enter "Done" in Col O when appointment is created
End If
r = r + 1
Loop
End Sub


The "Done" entry is to stop entries being duplicated upon subsequent runnings of the code

Thanks in advance for any help
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi VexedVBA,

Welcome to MrExcel!!

Which column to you want to check if it's blank or not?

Robert
 
Upvote 0
Though you could simply use this:

Code:
If(Cells(r, 8).Value) > 0

I did a revamp of your code as I had some trouble following it and came up with this:

Code:
Option Explicit
Sub AddSetOutlookAppointments()

    '//As this code uses early binding, a reference to 'Microsoft Outlook n.nn Object Library' is required //

    Dim lngMyRow As Long
    Dim lngEndRow As Long
    Dim myOutlook As Outlook.Application
    Dim myApt As Outlook.MailItem
    
    'Find the last row from columns H to O (these seem to be your dataset - change to suit)
    lngEndRow = Range("H:O").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    'Create the Outlook session
    Set myOutlook = CreateObject("Outlook.Application")
    
    For lngMyRow = 2 To lngEndRow 'Start at row 2
        
        If Len(Range("H" & lngMyRow).Value) > 0 Then

            ' Create the AppointmentItem
            Set myApt = myOutlook.createitem(olMailItem)
            ' Set the appointment properties
            With myApt
                .Subject = Range("H" & lngMyRow).Value
                .Location = Range("I" & lngMyRow).Value
                .Start = Range("J" & lngMyRow).Value
                .Duration = Range("K" & lngMyRow).Value
                ' If Busy Status is not specified, default to 2 (Busy)
                If Trim(Range("L" & lngMyRow).Value) = "" Then
                    .BusyStatus = 2
                Else
                    .BusyStatus = Range("L" & lngMyRow).Value
                End If
                If Range("L" & lngMyRow).Value > 0 Then
                    .ReminderSet = True
                    .ReminderMinutesBeforeStart = Range("M" & lngMyRow).Value
                Else
                    .ReminderSet = False
                End If
                .Body = Range("O" & lngMyRow).Value
                .Save
                Range("P" & lngMyRow).Value = "Done" 'Enter "Done" in Col O when appointment is created
            End With
            
        End If
    
    Next lngMyRow
    
    Set myOutlook = Nothing
    Set myApt = Nothing

End Sub

Regards,

Robert
 
Upvote 0
Hi rob, thanks for your ongoing help

i am getting a "run time error 438 - Object doesn't support this property or method"
 
Upvote 0
2hi6x6o.jpg
[/IMG]
 
Upvote 0
i am getting a "run time error 438 - Object doesn't support this property or method"

Which line?

If you can't my code to work just incorporate the IF statement I posted.
 
Last edited:
Upvote 0
To help you visualize what i am trying to achieve to the left of the bar i record all calls etc, on the right of the bar i highlight only those i wish to make a calendar entry of, the difficulty comes when they're are gaps between entries.

Your help is very much appreciated
 
Upvote 0
Where would i incorporate "If(Cells(r, 8).Value) > 0", i assume i replace or alter "Do Until Trim(Cells(r, 8).Value) = "" ?
 
Upvote 0
Try this:

Code:
' Create the Outlook session
    Set myOutlook = CreateObject("Outlook.Application")
    
    ' Start at row 2
    r = 2
    
    Do Until r = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
    
        If Len(Cells(r, 8)) > 0 Then
        
            If Cells(r, 8).Value <> "Done" Then
            
                ' Create the AppointmentItem
                Set myApt = myOutlook.createitem(1)
                ' Set the appointment properties
                myApt.Subject = Cells(r, 8).Value
                myApt.Location = Cells(r, 9).Value
                myApt.Start = Cells(r, 10).Value
                myApt.Duration = Cells(r, 11).Value
                ' If Busy Status is not specified, default to 2 (Busy)
                If Trim(Cells(r, 12).Value) = "" Then
                    myApt.BusyStatus = 2
                Else
                    myApt.BusyStatus = Cells(r, 12).Value
                End If
                If Cells(r, 13).Value > 0 Then
                    myApt.ReminderSet = True
                    myApt.ReminderMinutesBeforeStart = Cells(r, 13).Value
                Else
                    myApt.ReminderSet = False
                End If
                myApt.Body = Cells(r, 14).Value
                myApt.Save
                Cells(r, 15) = "Done" 'Enter "Done" in Col O when appointment is created
            
            End If
            
        End If
        
    r = r + 1
    
    Loop
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,108
Members
452,302
Latest member
TaMere

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