+ Reply to Thread
Results 1 to 6 of 6

Select Case within For loop not copying sheets to a new workbook

  1. #1
    Registered User
    Join Date
    08-06-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    5

    Select Case within For loop not copying sheets to a new workbook

    Greetings from an amateur VBA coder.

    I'm trying get VBA to create a new workbook where I only want to pluck 7 values from the column I'm evaluating (column C). The values are "IMA HIGH", "IMA HIGH (CCI)", "IMA CDN", "IMA BAL", "IMA BAL (CCI)", "IMA NA" and "IMA US". The column won't always have all 7 of these values, which is fine, I only want the info if ANY appear. I took existing code from another module that copies new workbooks properly. Then tried to create a For Loop that specifically evaluates the range and then Select Case to copy other worksheets in the existing workbook to a new workbook if the value shows up in the list

    The current challenges:
    - I haven't had any success in getting the data copied over without it copying the same worksheet over and over.
    - I am unsure if my Case parameters are properly differentiated (ie. will "IMA HIGH" also cause the "IMA HIGH (CCI)" worksheet to be copied over as well)
    - My preference is to have the For loop read the C range until it reaches the end of the list as opposed to having a set range

    The code I have so far is the base I've been working from, any pointers are greatly appreciated,
    Dan


    Please Login or Register  to view this content.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Select Case within For loop not copying sheets to a new workbook

    This is a guess without seeing your workbook but since you're looping through column C do you want
    Please Login or Register  to view this content.
    to offset 1 column instead of a row?

    Why offset at all if your select case is based on your variable and the offset statement doesn't select any or change the variable?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Dan

    Which workbook and worksheet is the range you are looping through supposed to be on?

    Also, what's the purpose of the With statement?

    As far as I can see it doesn't do anything.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    08-06-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Select Case within For loop not copying sheets to a new workbook

    XeRo Solus thanks for the reply. I want it to read only the cells in the C column. Am I incorrect in using the offset?

  5. #5
    Registered User
    Join Date
    08-06-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Select Case within For loop not copying sheets to a new workbook

    Norie, the workbook and worksheet I'm trying to loop through is the existing one. Hoping to get the loop to copy the data I need into the new workbook via the loop

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    As it is the code is looping through a range on the active sheet of the active workbook.

    When you create a new workbook it becomes the active workbook.

+ 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] Using a loop with Select Case
    By greglittle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2012, 10:45 AM
  2. [SOLVED] Select Case with a Loop
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2012, 01:50 PM
  3. Select Case in a loop something like this possible?
    By scottr99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2012, 05:31 PM
  4. Select Case with Loop or For Next
    By garretonufer in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-24-2009, 07:12 AM
  5. How to use Select Case in a loop
    By mikea3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2008, 02:09 AM

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