+ Reply to Thread
Results 1 to 6 of 6

Loop to repeat macro on column cells

  1. #1
    Registered User
    Join Date
    05-28-2010
    Location
    Egypt
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    5

    Loop to repeat macro on column cells

    I want to repeat the below code on range of cells on column A and want the code discard when reached empty cell. and change the path of saving the files to F:\

    N.B: The below code work perfictly with one cell and save the file in my documents.

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Need to loop to repeat macro on column cells

    See if you can use the following.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-28-2010
    Location
    Egypt
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    5

    Re: Need to loop to repeat macro on column cells

    It does not work even after I add next a to the code

  4. #4
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Need to loop to repeat macro on column cells

    Hi samy_mero;
    This macro will do what you ask, but it won't do what you want. It keeps saving the file to the same file name over and over. The filename to save it to is located in C5 and it never changes.

    I put in my own comments where I changed things that were pointless
    The format for my comments is like this:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  5. #5
    Registered User
    Join Date
    05-28-2010
    Location
    Egypt
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    5

    Re: Need to loop to repeat macro on column cells

    It give me error in

    ActiveWorkbook.SaveAs Filename:=Sheets(WSName).Range(CName).Text

  6. #6
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Need to loop to repeat macro on column cells

    Hi samy_mero;

    I did not change that line from your code. Since I can't test it, I may not be able to tell you how to fix it.

    You can try this:
    Just before the line that crashes put this:
    Please Login or Register  to view this content.
    Then run the macro by clicking F8. This will step through the code one line at a time. When it gets to the line that crashes:
    Click Ctrl+G to open the immediate window.
    type "? s" (without the quote marks) and hit enter.
    The name of the file that is about to be saved will be printed right below the "? s".
    Check to see if that file already exists.
    Then click F8 to step one more line and see if it crashes.
    If it doesn't crash then keep clicking F8 until it comes back to the same line.
    Again ? s in the immediate window and see if the file already exists.

    If it crashes, record the Error # and Description. Maybe someone can figure out what it means.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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