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:
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,832
Messages
5,855,890
Members
431,772
Latest member
dannyboi1

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