VBA email script doing weird....

Lukums

Board Regular
Joined
Nov 23, 2015
Messages
195
Hey guys... my script is doing weird things and can't workout why!

What is happening when ALL rows = correct criteria and the email function triggers it's actually placing "DONE" against all lines... instead of just that Row (i).... and moving down to the next.

The thing is I'm only saying to do this in "E" as a once off so I can't workout the function.

Code:
Sub SendMail()

Dim i As Long
Dim lastrow As Integer
   
lastrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row


Sheets("Sheet1").Select


For i = 4 To lastrow


 If Sheets("Sheet1").Range("D" & i).Value <= 7 Then
        Sheets("Sheet1").Range("E" & i).Value = "DONE"
        ActiveWorkbook.FollowHyperlink "mailto:" & Cells(i, 1) & _
        "?Subject=Shed to be delivered shortly&Body=Dear " & _
        Cells(i, 2) & ", Your shed has been scheduled for DELIVERY within the next 7 DAYS if you need to make any changes to please please contact xxx immediately on (02) xxx The delivery date is " & _
        Cells(i, 3) & "."
    End If
next i
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Re: vBA email script doing weird....

Not sure if it is related but is Sheet1 the Activesheet ?
If not your code will find the lastrow of whatever sheet is active BEFORE SHeet1 is selected !!
Maybe this would be better....UNTESTED

Code:
Sub MM1()
Dim i As Long, lastrow As Long
lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
With Sheets("Sheet1")
    For i = 4 To lastrow
     If .Range("D" & i).Value <= 7 Then
            .Range("E" & i).Value = "DONE"
            ActiveWorkbook.FollowHyperlink "mailto:" & Cells(i, 1) & _
            "?Subject=Shed to be delivered shortly&Body=Dear " & _
            .Cells(i, 2) & ", Your shed has been scheduled for DELIVERY within the next 7 DAYS if you need to make any changes to please please contact xxx immediately on (02) xxx The delivery date is " & _
            .Cells(i, 3) & "."
        End If
    Next i
End With
End Sub
 
Upvote 0
Re: vBA email script doing weird....

Hey Michael,

No good does exactly the same thing.

It's flagging ALL other lines if <= 7 as DONE. Which is super weird...

It only flags when: This triggers:

ActiveWorkbook.FollowHyperlink "mailto:" & Cells(i, 1) & _
"?Subject=Shed to be delivered shortly&Body=Dear " & _
.Cells(i, 2) & ", Your shed has been scheduled for DELIVERY within the next 7 DAYS if you need to make any changes to please please contact xxx immediately on (02) xxx The delivery date is " & _
.Cells(i, 3) & "."
End If
Next i
 
Upvote 0
Re: vBA email script doing weird....

Is <= 7 a calculation ??
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,961
Members
452,539
Latest member
delvey

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