+ Reply to Thread
Results 1 to 5 of 5

I need a macro that will let me loop a section of the vba code x number of times

  1. #1
    Registered User
    Join Date
    01-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    5

    I need a macro that will let me loop a section of the vba code x number of times

    I don't know why I'm having problems with this I'm positive I have done this before

    Thank you for your help

    I have a macro that simply copies data (sku#, price, size ect) from sheet 1 row 1, and pastes it in sheet 2, then prints sheet 2 (as a formatted sign).
    Then copies data from sheet 1 row 2 and pastes that into sheet 2 and prints.

    I'm trying to find a way to be able to tell the macro i want to repeat X number of times (Either from a value in a cell or dialog from a macro) and have it loop back to towards the start of the macro (but not the very start)


    here is the code


    Sub Relative()
    '
    ' Relative Macro
    '

    '
    Sheets("SIGN").Select
    Range("A2:N23").Select
    Selection.ClearContents

    Sheets("INFORMATION").Select
    Range("B4").Select

    (THIS IS WHERE I NEED MY LOOP IN POINT)

    Selection.Copy 'Copy Value SQFT
    Sheets("SIGN").Select '##SIGN## Sheet
    Range("J29:M30").Select 'SQFT/PIECE cell
    ActiveSheet.Paste 'Paste Value SQFT

    Sheets("INFORMATION").Select '##INFORMATION Sheet
    ActiveCell.Offset(0, 1).Range("A1").Select 'Move right 1 cell
    Application.CutCopyMode = False 'Release copy mode
    Selection.Copy 'Copy Value SKU
    Sheets("SIGN").Select '##SIGN## Sheet
    Range("K35:M36").Select 'SKU cell
    ActiveSheet.Paste 'Pase Value SKU


    Sheets("INFORMATION").Select '##INFORMATION Sheet
    ActiveCell.Offset(1, -11).Range("A1").Select '&&&&& Carige Return &&&&&
    Application.CutCopyMode = False 'Release copy mode


    (THIS IS WHERE I NEED IT TO LOOP BACK TO THE TOP)

  2. #2
    Registered User
    Join Date
    01-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: I need a macro that will let me loop a section of the vba code x number of times

    sorry here is the code with out my comments


    Sub Relative()
    '
    ' Relative Macro
    '

    '
    Sheets("SIGN").Select
    Range("A2:N23").Select
    Selection.ClearContents

    Sheets("INFORMATION").Select
    Range("B4").Select

    (THIS IS WHERE I NEED MY LOOP IN POINT)

    Selection.Copy
    Sheets("SIGN").Select
    Range("J29:M30").Select
    ActiveSheet.Paste

    Sheets("INFORMATION").Select
    ActiveCell.Offset(0, 1).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("SIGN").Select
    Range("K35:M36").Select
    ActiveSheet.Paste


    Sheets("INFORMATION").Select
    ActiveCell.Offset(1, -11).Range("A1").Select
    Application.CutCopyMode = False


    (THIS IS WHERE I NEED IT TO LOOP BACK TO THE TOP)

  3. #3
    Registered User
    Join Date
    05-22-2010
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    12

    Re: I need a macro that will let me loop a section of the vba code x number of times

    Hi Tuckejam,

    Here's a loop counter that I have. You could place your code in the middle of it and test it to see if it works how you need.

    There's an inputbox to get the amount of times to loop. Or it would be pretty easy to set a cell value to the variable 'LoopTimes' if you need it that way.



    Please Login or Register  to view this content.
    Good Luck

  4. #4
    Registered User
    Join Date
    01-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: I need a macro that will let me loop a section of the vba code x number of times

    Absolutely Fantastic

    Thank You

  5. #5
    Registered User
    Join Date
    05-22-2010
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    12

    Re: I need a macro that will let me loop a section of the vba code x number of times

    No worries

    If you need to set a cell's value as the number of times to loop, just change this line:

    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.
    You just need to insert your own sheet name and the cell address.

+ 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