+ Reply to Thread
Results 1 to 13 of 13

Need a Macro to loop through an If Then Statement. Can't get mine to work

  1. #1
    Registered User
    Join Date
    06-24-2014
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    12

    Question Need a Macro to loop through an If Then Statement. Can't get mine to work

    Hey guys!

    I am looking for a looping macro that will find a name in Column A and copy into the blank cells below until it comes to the next name and then repeat process. It would finally come to an end when there is no date found in Column C. Here's a sample of the data I'm working with.

    Capture.PNG

    Any help?

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    No looping needed:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    06-24-2014
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    12

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    Thanks for the quick reply Bernie!

    I had tried this before, but the issue is this will continue to fill the last name in Column A all the way down. I need it to stop when there is no date in Column C and no name in Column A. There is data in Column A through M. I have a macro set up to copy all data in those columns and when it is pasted on my other sheet, I can't have the names listed all the way down. Just those names on the same rows as the other data.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    Normally, that will only work on the usedrange, so that will not fill the entire column. But you can limit the fill to match column C like so:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-17-2014
    Location
    DUbai
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    Try This
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-24-2014
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    12

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    Almost guys!!

    Both of the macros did what it needed in the sense that the names were filled in just until the other data ended in Column C. BUT, it filled in just the first name instead of filling the blanks with the name above them. See image below....

    Capture2.PNG

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    Oops = sorry, I "withed" one level too low! I guess I should actually run the code I write....

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-24-2014
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    12

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    You are awesome Bernie!! Thank you! This is perfect!

  9. #9
    Registered User
    Join Date
    04-17-2014
    Location
    DUbai
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-24-2014
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    12

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    Okay Bernie, I have another conundrum for you!

    Senario...
    People can buy one or two of my products and when I pull a report from an outside source it has two products listed for those individuals that purchased second. I am having to rearrange the data in a way that conforms to the spreadsheet I have. See image.....

    Capture1.PNG

    Here's what I need, and hopefully can make happen. I need a macro to search the second product column, Column H. If it finds a cell that has a second product listed, copy that row(A? through V?) and paste it on the next blank row below my data. I'm running around in circles here trying to figure this one out.

    Thanks!

  11. #11
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    Do you want it moved, or copied? Or just be easily found together? It is generally bad practice to make copies, and moving is not really needed. If you apply data filters to your column H, and uncheck Blanks, then only rows with second products will be shown. You could also sort your entire table by column H to move blanks to the top or bottom, and values to the bottom or top. Either of those can be done without macros.

  12. #12
    Registered User
    Join Date
    06-24-2014
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    12

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    Unfortunately, I need it copied. There is a master workbook that all of this will be copied into so that we can add it to other metrics and extrapolate all sort of statistics.

  13. #13
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: Need a Macro to loop through an If Then Statement. Can't get mine to work

    Try it like this, after you fix the names for the Master workbook and the data sheet within - I have assumed that the Master workbook will already be open, and that column A will be filled.

    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. [SOLVED] Need help writing a macro for work that can loop through reference numbers
    By Easy88 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-14-2014, 11:55 AM
  2. [SOLVED] Trouble with macro - Loop through all work sheets
    By RichTea88 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-06-2013, 05:23 AM
  3. 'lastrow =' How long does statement 'work' in macro?
    By BEEJAY in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-12-2012, 08:39 AM
  4. My loop macro doesnt work
    By matdog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2010, 02:32 AM
  5. [SOLVED] Macro/Loop If Statement Help -delete the row with the specific te
    By Bricktop in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-28-2005, 06:05 PM

Tags for this Thread

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