For Next loop...or whatever works

ammdumas

Active Member
Joined
Mar 14, 2002
Messages
469
I'm horrible with for / next loops.

I've got code that emails a notification and adds cell data to the body of the message (thanks to the board for info on that). I've already set up the sheet to add 'PAST DUE' when a date is past.

Now I want cycle through the sheet to look for "PAST Due" in Column N and send an email with data from Columns C, J, and K. I know where it goes (to be done upon opening the sheet). I just need the before and after stuff to do the cycling. I'm pretty sure the body of the email would be a variable instead of Range("cell").Text as part of the cycling. Any help would be greatly appreciated. :ROFLMAO:
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello,

will this code work for you?

Code:
Sub FIND_PAST_DUE()
For MY_ROWS = 1 To Range("N65536").End(xlUp).Row
If Range("n" & MY_ROWS).Value = "PAST Due" Then
 'YOUR CODE HERE
End If
Next MY_ROWS
End Sub
 

ammdumas

Active Member
Joined
Mar 14, 2002
Messages
469
Sweet. It worked. Now how do I change the body of the text to reflect each row of data that is sent? (i.e. certain cells for each row that is 'Past Due'). Obviously Range("C3").Text is only going to print that one row X number of times...
 

ammdumas

Active Member
Joined
Mar 14, 2002
Messages
469

ADVERTISEMENT

Doh! Not working. I get runtime error 1004

"Method 'Range' of object '_global' failed"

Here's the code (you can see where I added your little bit). Where I had 'Range("C3").Text' (in the .Body which worked) I put your 'Range("C") & MY_ROWS' (for the three peices of data I'm copying)..

With objTask
.Subject = "Overdue Action Notice"
.Body = "***NOTICE***" & Chr(13) & Chr(13) & "This is to inform you that your action for " & Range("C") & MY_ROWS & " to " & Range("K") & MY_ROWS & Chr(13) & "was expected back by " & Range("J") & MY_ROWS & "." & Chr(13) & Chr(13) & "Please contact the sender (as indicated on the transmittal) immediately to arrange completion of this action."
.Recipients.Add ("name@domain.com")
.Send
End With

Argh.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,214
Messages
5,594,881
Members
413,947
Latest member
gizmolucy

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
Top