+ Reply to Thread
Results 1 to 8 of 8

How do extend macro to multiple rows

  1. #1
    Registered User
    Join Date
    05-28-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    7

    How do extend macro to multiple rows

    I have a macro running within a single row (about 100 if statements with various results) I would like it to run through more then one. currently it is running and sending an email in outlook based on various values. I would like to have it produce emails for each person (ie. more then one row) do you know how I can run my macro through each row with a simple add in my code?

    thanks,
    A

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How do extend macro to multiple rows

    There's a number of ways you do it. I usually go with For Each


    Please Login or Register  to view this content.
    This will run for each cell in A2:A50, one at a time, then cycle to the next cell and repeat your do stuff.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    05-28-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: How do extend macro to multiple rows

    I have imported that into my code and it is giving me invalid outside procedure this is my code..could you point me in the right direction

    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: How do extend macro to multiple rows

    I get the feeling you want to: run a macro that processes each cell, then basically move down a row and do the same... until last row in a range? This might help:

    Please Login or Register  to view this content.
    hth, Arkadi
    Last edited by Arkadi; 02-13-2014 at 01:54 PM.

  5. #5
    Registered User
    Join Date
    05-28-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: How do extend macro to multiple rows

    not each cell only the selected cells which are defined Globally at the start of the code

  6. #6
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How do extend macro to multiple rows

    You already have While in there for each nRow.

    Perhaps Do While instead, and end with Loop instead of Wend?


    Please Login or Register  to view this content.
    Your nRow + 1 at the bottom would increment the row value, and then move onto the next cell.

    Do While -- Loop is another looping expression, similar to For [Each] -- Next. It has a lot to do with how things are defined.


    For example:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    These both do the same thing, but one declares its range with Do While with an incrementing row value, while my For Each didn't. What's important is the first column of data that it is checking against. For is essentially checking a single column for data or if it's in a specific range, and then for every row of that cell do something until it runs out.
    Last edited by daffodil11; 02-13-2014 at 02:08 PM.

  7. #7
    Registered User
    Join Date
    05-28-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: How do extend macro to multiple rows

    I am a little confused on how to approach this, I am not the best with VBA so I apologize if I seem out to lunch haha. I understand what your saying but that is not really what I want it to do...Ithink. I want it to check columns in a row and for how every many cells are TRUE, which then emails the person (the email is in the first row). then I want it to jump down to row 2,3,4,5,etc. and do the same thing and send them emails as well.

  8. #8
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How do extend macro to multiple rows

    The point of the For and Do is to find out which rows of a column. The other columns don't even matter.

    If code were to simply go from one cell to the next, it would run down 1.04 million rows. You don't want that, you have things to do in this life. So we check which cells in your name column have a name; we will do something to those rows. For each row with a name, go do the other stuff; when we run out of names, stop doing stuff or your computer is going to be thinking for a very very long time. Also would propably hitting a lot of Outlook errors too trying to send emails to no one.

    So, for each cell in A? if A has a name, we go and do things. It does the stuff, sends the mails. We check the next cell in A. Does it have something? Do it all again. When we run out names, we need to stop going to the next.

+ 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. How to extend formulas from (say) 3 rows to many rows?
    By iVenky in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-26-2013, 05:17 AM
  2. [SOLVED] Macro to extend formula with sum of every other two rows
    By mmchung in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-18-2013, 07:17 AM
  3. Extend the number of rows in the List Box
    By Excel_Kidz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-29-2011, 04:41 AM
  4. How do I extend worksheet to 1 million rows?
    By mrmag2000 in forum Excel General
    Replies: 2
    Last Post: 05-20-2009, 08:03 PM
  5. [SOLVED] Extend Formulas to Inserted Rows
    By AC in forum Excel General
    Replies: 2
    Last Post: 07-19-2006, 05:30 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