+ Reply to Thread
Results 1 to 8 of 8

Novice with VBA and macro writing needing help to loop a macro unti no data

  1. #1
    Registered User
    Join Date
    07-23-2013
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 2010
    Posts
    4

    Novice with VBA and macro writing needing help to loop a macro unti no data

    Greetings,

    I am attempting to write a macro in Excel 2010 that pulls a lengthy number of specifications data from a master list and copy/pastes that data into new tabs. Each new tab will be for one specification (IE: Oxygen Level) and will list all the lot numbers and their respective data for that specification. I have written the VBA code to pull everything I need and copy/paste into new tabs etc., but what I cannot do, is to write it in that the macro loops or continues to pull, copy/paste for EACH lot for each specification. My macro is only able to preform the task for the 1st lot number only and then stops.

    Here is a sample of my code:

    Sub ComplianceMacroTest()
    '
    Application.ScreenUpdating = False

    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets("Data").Range("A6:F7").Copy Destination:=Worksheets(Sheets.Count).Range("A6")
    Sheets("Data").Range("C1:F5").Copy Destination:=Worksheets(Sheets.Count).Range("C1")
    Sheets("Data").Range("A8:F8").Copy Destination:=Worksheets(Sheets.Count).Range("A8")
    Cells.Columns.AutoFit
    Cells.Columns.HorizontalAlignment = xlCenter


    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets("Data").Range("A6:F7").Copy Destination:=Worksheets(Sheets.Count).Range("A6")
    Sheets("Data").Range("G1:J7").Copy Destination:=Worksheets(Sheets.Count).Range("C1")
    Sheets("Data").Range("A8:F8").Copy Destination:=Worksheets(Sheets.Count).Range("A8")
    Sheets("Data").Range("G8:J8").Copy Destination:=Worksheets(Sheets.Count).Range("C8")
    Cells.Columns.AutoFit
    Cells.Columns.HorizontalAlignment = xlCenter

    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets("Data").Range("A6:F7").Copy Destination:=Worksheets(Sheets.Count).Range("A6")
    Sheets("Data").Range("K1:N7").Copy Destination:=Worksheets(Sheets.Count).Range("C1")
    Sheets("Data").Range("A8:F8").Copy Destination:=Worksheets(Sheets.Count).Range("A8")
    Sheets("Data").Range("K8:N8").Copy Destination:=Worksheets(Sheets.Count).Range("C8")
    Cells.Columns.AutoFit
    Cells.Columns.HorizontalAlignment = xlCenter

    The "Data" sheet has all of the specifications on one sheet and lists all lot numbers in column B. The rest of the code is written to find and copy/ paste the first lot for each specification and then paste it into a new tab with the header and criteria for that specification. I am just honestly awful at macro writing but know enough to be dangerous! LOL. Any help you can provide would amazing! Thanks so much in advance.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,858

    Re: Novice with VBA and macro writing needing help to loop a macro unti no data

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    07-23-2013
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Novice with VBA and macro writing needing help to loop a macro unti no data

    My apologies..... please see updated and code tagged original message below.

    Thanks so much.

    Quote Originally Posted by jrongone View Post
    Greetings,

    I am attempting to write a macro in Excel 2010 that pulls a lengthy number of specifications data from a master list and copy/pastes that data into new tabs. Each new tab will be for one specification (IE: Oxygen Level) and will list all the lot numbers and their respective data for that specification. I have written the VBA code to pull everything I need and copy/paste into new tabs etc., but what I cannot do, is to write it in that the macro loops or continues to pull, copy/paste for EACH lot for each specification. My macro is only able to preform the task for the 1st lot number only and then stops.

    Here is a sample of my code:

    Please Login or Register  to view this content.
    The "Data" sheet has all of the specifications on one sheet and lists all lot numbers in column B. The rest of the code is written to find and copy/ paste the first lot for each specification and then paste it into a new tab with the header and criteria for that specification. I am just honestly awful at macro writing but know enough to be dangerous! LOL. Any help you can provide would amazing! Thanks so much in advance.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,359

    Re: Novice with VBA and macro writing needing help to loop a macro unti no data

    I think the preference might have been to add Code Tags around just the code in your original post rather than repeating the content and marking it all up


    I never understand why people want to create multiple sheets with the same or similar layout, formatting and formulae and the split the data amongst them. You are far better if you keep all your raw data in one table in one sheet. You can then create Tables, charts, Pivot Tables, sort it, filter it, group it, subtotal it ... whatever, you can slice and dice it however you want. Once you split it up it is much harder to bring together and analyse it ... which I suspect that you will want/need to do.

    And people will add columns, delete columns, hide columns, change formulae ... nightmare.

    And you're likely to need less code, if any, because the data can be processed using Excel's built in features ... which has to be a bonus if you're not very experienced with VBA.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    07-23-2013
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Novice with VBA and macro writing needing help to loop a macro unti no data

    Although I do appreciate your reply, the reasons for this test project are solely learning based as I am attempting to teach myself some pertinent tools to help me with projects I will have in the near future at my current job. I know excel very well.... I work with pivot tables and trend charts and SPC data and can manipulate excel based data fairly well. What I do not know is VBA,..... so thank you for the reply, but it was not helpful at all.

    Cheers!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,359

    Re: Novice with VBA and macro writing needing help to loop a macro unti no data

    I'm sorry if I have offended you and that my response was unhelpful in the circumstances.

    Fair enough. From a practical point of view, I have always found it more effective to set myself a challenge and overcome each of the hurdles it presents as I encounter them. That adds pressure, obviously, but it really helps focus the mind. Trying to learn something "with a view to applying it in the future" gives you less of an incentive to learn, I believe.

    This is a slightly different way of copying the data across.

    It's more scaleable and maybe easier to see where the source and target addresses are.

    This approach uses arrays to store the source and target addresses and you can loop through them. It is possible to enter the addresses into a worksheet and load them into the arrays ... and you could make each of them 2-dimensional. You'd loop through 1 dimension to create the sheets and the second to populate the cells.

    If you step through the code, I think you will see that you overwrite the data ... I don't know if that is intentional.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-23-2013
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Novice with VBA and macro writing needing help to loop a macro unti no data

    Thanks so much TMSHucks, and no worries. I didn't take offense.

    I will give this code a shot and see what I can do with it. Thanks again for the lesson and the help, I truly appreciate it. I'll let you know how I make out!

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,359

    Re: Novice with VBA and macro writing needing help to loop a macro unti no data

    You're very welcome. Thanks for the rep.

+ 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. Performing Multiple Commands in a single macro (Macro novice here!)
    By yankeesrus07 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-10-2012, 02:58 AM
  2. Writing macro that inputs data after last row, then sorts
    By PinkMafia14 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-29-2011, 08:00 AM
  3. writing a data inputting macro.
    By skatmandu2002 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-18-2010, 09:22 PM
  4. novice needing help on formula
    By jordiman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2009, 08:25 AM
  5. writing a macro to produce data for different intervals
    By fodeps in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-23-2008, 06:18 AM

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