+ Reply to Thread
Results 1 to 16 of 16

Macro loop struggles

  1. #1
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Macro loop struggles

    Hi guys!

    Is it possible to loop one single cell, lets say T1, in order to give it different values? For example: T1=1, loop, T1=2, loop, T1=3, loop

    I tried to do it like this:

    Please Login or Register  to view this content.
    I want the loop to first define T1 as 1 then the following macro can take place:

    Please Login or Register  to view this content.
    Then loop to T1=2

    Thanks in advance!

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,192

    Re: Macro loop struggles

    You would use Range, if you know the letter ,

    For I = 1 to 6
    Range("T" & I).value

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Macro loop struggles

    Maybe this would work :
    Please Login or Register  to view this content.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Macro loop struggles

    You can't do it that way... it would be:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro loop struggles

    It doesn't work! It says compile error: next without for.. Can you see what is going wrong?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Macro loop struggles

    Next i should come after End With...:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Macro loop struggles

    But there is another issue here I think... each i will create a new outlook application instance, and sh did not exist in the macro so I have added it. Try this (changes in red):

    Please Login or Register  to view this content.
    Last edited by Arkadi; 02-22-2017 at 12:59 PM.

  8. #8
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro loop struggles

    Thanks Arkadi! That kind of worked, however the next problem it states is that the item has been moved or deleted and it references to the "to" part, which the attachment will be sent to by Outlook.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Macro loop struggles

    Are you able to provide a workbook with sample data? Is it possible that the value in T24 is not the location (full path and filename) of the attachment?

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Macro loop struggles

    Ik zie dat het "savepath" in T18 staat, en "saveas" in T19... wat staat er in T24? een combinatie van die twee?
    Last edited by Arkadi; 02-24-2017 at 09:33 AM.

  11. #11
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro loop struggles

    This is the worksheet! T24 is the precise name of the document. I read somewhere online that it could be due to the fact that the PDF and Email are both made in a different loop, which could give trouble. Do you have any experience with this or do you think it is something else?
    Excel sheet.png

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Macro loop struggles

    Hi again.... I see t24 has a filename... But isnt t25 the cell with the complete filename including c:\.........\xxx.pdf?
    But yes.... They should be in same loop... The way it is now all emails would have last pdf as attachment.
    Im on my phone.... When i get to a computer (2 hrs) i will look further.

  13. #13
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro loop struggles

    You are right, I added a line so it should be T25. But that does not solve the problem. It sends the attachment and e-mail to i=1 but not to i=2,3,4,5,6, etc.

    So it only sends the first e-mail..

    Thanks Arkadi! Btw are you Dutch?

  14. #14
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Macro loop struggles

    Hi Jstns,

    Yes I'm Dutch, though I left when I was very young. (But will ALWAYS cheer for Oranje!)

    As for the code, try this.... Note I created the outlook instance before the loop, since you don't need to open it every time. I also put a few notes because I think your subject and body rows are mistaken? Also.... I see you are changing T1 every time, does that mean the cell T8 has a formula so that the email address changes each time? Just curious.


    Please Login or Register  to view this content.
    Last edited by Arkadi; 02-24-2017 at 09:41 AM.

  15. #15
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro loop struggles

    Thanks Arkadi! It worked! You are a lifesaver. How can I set a print area within the macro?

  16. #16
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Macro loop struggles

    My pleasure

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro loop struggles
    By Jstns in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2017, 09:12 AM
  2. [SOLVED] Beginner help with VBA | Struggles with attachments to email
    By Jstns in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-17-2017, 06:38 AM
  3. [SOLVED] SUMIF with INDEX MATCH struggles
    By Glower0617 in forum Excel General
    Replies: 2
    Last Post: 06-23-2016, 11:37 AM
  4. New to Excel - Conditional Formatting struggles.
    By southaja in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-15-2016, 03:53 PM
  5. Replies: 1
    Last Post: 06-05-2013, 12:11 PM
  6. [SOLVED] custom dll struggles
    By Paul in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-15-2006, 10:00 AM
  7. [SOLVED] Struggles with Numercial Sorting. Please Help.
    By mtbakerstu in forum Excel General
    Replies: 1
    Last Post: 05-03-2006, 07:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1