+ Reply to Thread
Results 1 to 11 of 11

Need some help geting VBA code to work back to back.

  1. #1
    Registered User
    Join Date
    03-12-2013
    Location
    Palo Alto, CA
    MS-Off Ver
    Excel 2010
    Posts
    20

    Need some help geting VBA code to work back to back.

    I have two sets of code. The first sets of code takes seperate excel spreadsheets and consolidates it into one excel spreadsheet with seperate tabs. The second code takes the tabs C1's thru C10's B32:B3032 Coloumns and sets them as seperate coloumns in a tab that i have to create called C. I would like to make it so I don't have to use two sets of code but don't know how. If anyone has the solution, I would greatly appreciate it.



    Please Login or Register  to view this content.
    Last edited by vlady; 03-13-2013 at 07:36 PM.

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

    Re: Need some help geting VBA code to work back to back.

    Which workbook do you want to run SummurizeSheets on?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    03-12-2013
    Location
    Palo Alto, CA
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Need some help geting VBA code to work back to back.

    I would like to run summerizeSheets on Consolidated.xlsx

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Need some help geting VBA code to work back to back.

    I do not see your problem.

    All you do is paste the code within the second macro into the bottom of the first.

    Am I missing something?

    Please Login or Register  to view this content.
    Last edited by vlady; 03-13-2013 at 07:36 PM.

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

    Re: Need some help geting VBA code to work back to back.

    You should just be able to add this at the end of Macro1.
    Please Login or Register  to view this content.
    Mind you, instead of copying the worksheet from the workbooks you are opening you could just copy the range.
    Please Login or Register  to view this content.

    PS Could you please add code tag? It was hard to see where one sub ended and the other started, tags would make that easier.

    Oh, and I think adding code tags is kind of a rule too.

  6. #6
    Registered User
    Join Date
    03-12-2013
    Location
    Palo Alto, CA
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Need some help geting VBA code to work back to back.

    Thanks for the response and I'll remember to use code tags for future postings. I'm not an experienced code writer and when I tried using your suggested code below I got the following error. Run-time error '9': Subscript out of range. It didn't like newWb.Sheets(ctr).Name = CStr(elem)

    Option Explicit

    Please Login or Register  to view this content.
    Last edited by vlady; 03-13-2013 at 07:37 PM.

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

    Re: Need some help geting VBA code to work back to back.

    That line isn't needed any more as you aren't copying sheets from the workbooks.

  8. #8
    Registered User
    Join Date
    03-12-2013
    Location
    Palo Alto, CA
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Need some help geting VBA code to work back to back.

    It's almost seems to be working correctly. However, in the new created workbook Consolidated it listed A1:B3032 from C1 instead of B32:B3032 from C1. C2, C3, C4, C5, C6, C7, C8, C9, and C10 are shown correctly shows data B32:B3032. Also, C2 overlaps B Coloumn data in B1. Do you have any idea what could be causeing this?

  9. #9
    Registered User
    Join Date
    03-12-2013
    Location
    Palo Alto, CA
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Need some help geting VBA code to work back to back.

    I think what it's doing is not creating a seperate sheet. It's overlaping the data B32:B3032 from C2, C3, C4, C5, C6, C7, C8, C9, C10 into the sheet C1 starting in coloumn B. How do I go about fixing this?

    Thanks again,
    Brett

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

    Re: Need some help geting VBA code to work back to back.

    Brett

    A new workbook is created by copying the first sheet of the first workbook.

    Then instead of copying worksheets from the rest of the workbooks just the range is copied from them to then new workbook.

    That might need a bit of a tweak to work properly, I can't tell without knowing more about the layout of the worksheets you are copying from.

    Did you try my initial suggestion?

  11. #11
    Registered User
    Join Date
    03-12-2013
    Location
    Palo Alto, CA
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Need some help geting VBA code to work back to back.

    Thank you very much Norie. You've been a lot of help. I just added a blank workbook to the folder and everything works okay now.

    Thanks again,
    Brett

+ 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