+ Reply to Thread
Results 1 to 12 of 12

VBA to loop through a list of string values

  1. #1
    Registered User
    Join Date
    08-09-2017
    Location
    Brisbane
    MS-Off Ver
    Office Home & Business 2016
    Posts
    21

    VBA to loop through a list of string values

    Hi, I have a Workbook with sheet names "110-actual", '213-actual", '566-actual"

    I want to copy and paste the 3 sheets to another workbook.

    How do I set up code to loop through a list like ("110","213","566"). The below doesn't work as Excel expects a ")" after "110"

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    05-12-2018
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    266

    Re: VBA to loop through a list of string values

    try this:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-21-2019
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    58

    Re: VBA to loop through a list of string values

    Hi,

    Please Login or Register  to view this content.

    Change the directory

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: VBA to loop through a list of string values

    Quote Originally Posted by mb1824 View Post
    Hi, I have a Workbook with sheet names "110-actual", '213-actual", '566-actual"

    I want to copy and paste the 3 sheets to another workbook.
    Try
    Please Login or Register  to view this content.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA to loop through a list of string values

    Here's one way

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  6. #6
    Registered User
    Join Date
    07-21-2019
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    58

    Re: VBA to loop through a list of string values

    Edit: sorry, I had the wrong thread
    Last edited by MrGes; 08-11-2019 at 06:47 AM.

  7. #7
    Registered User
    Join Date
    08-09-2017
    Location
    Brisbane
    MS-Off Ver
    Office Home & Business 2016
    Posts
    21

    Re: VBA to loop through a list of string values

    Hi all,

    Thanks for your comments. Unfortunately i forgot to specify that I want the 3 tabs copied to 3 individual workbooks. Apologies for any inconvenience

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA to loop through a list of string values

    Just adapt and put the workbooks.Add instruction inside the loop



    Please Login or Register  to view this content.
    Last edited by Richard Buttrey; 08-11-2019 at 07:22 AM.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: VBA to loop through a list of string values

    Quote Originally Posted by mb1824 View Post
    I want the 3 tabs copied to 3 individual workbooks.
    Simply
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-09-2017
    Location
    Brisbane
    MS-Off Ver
    Office Home & Business 2016
    Posts
    21

    Re: VBA to loop through a list of string values

    Sub test()
    Dim e
    For Each e In Array("101", "213", "566")
    ThisWorkbook.Sheets(e & "-actual").Copy
    Next
    End Sub

    Suppose in addition to "110-actual", '213-actual", '566-actual", I also have sheet names "110-budget","213-budget","566-budget".

    How do I modify your suggestion to copy "110-actual" and "110-budget" into 1 workbook, "213-actual" and "213-budget" into a 2nd workbook and "566-actual" and "566-budget" into a third workbook?

    I tried the below but it doesn't work
    Please Login or Register  to view this content.
    Last edited by mb1824; 08-11-2019 at 07:37 AM.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: VBA to loop through a list of string values

    You have extra open bracket. should be
    Please Login or Register  to view this content.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: VBA to loop through a list of string values

    Thanks for the rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ 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. Loop through the list and record values in another sheet
    By maorlov in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-27-2019, 10:04 AM
  2. Compare Range list with String Array list (both same # of values)
    By mgmAB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2016, 06:58 AM
  3. Replies: 2
    Last Post: 12-29-2014, 11:24 PM
  4. Sum values if other cell contains the same text string + loop
    By pollfre in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-30-2014, 10:25 AM
  5. Loop through list of data and calculate values
    By mccrimmon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-24-2010, 12:08 PM
  6. Loop using list of values
    By treva26 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2010, 02:01 PM
  7. Replies: 8
    Last Post: 12-08-2008, 12:54 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