+ Reply to Thread
Results 1 to 15 of 15

Combine 2 functions into 1 macro (VBA)

  1. #1
    Registered User
    Join Date
    06-17-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    14

    Combine 2 functions into 1 macro (VBA)

    I have a macro that does exactly what I need to do namely transpose some data from one sheet and copy it to an other sheet within the workbook.

    Please Login or Register  to view this content.
    I have a macro that loops true several excel files in one directory (open/close) them to perform an action. That code does exactly that namely open en close every workbook in that directoy.

    Please Login or Register  to view this content.
    My question is following;
    How to consolidate the two functions into one macro.

    Thanks for helping me.
    Last edited by NBVC; 09-09-2010 at 08:22 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Combine 2 functions into 1 macro (VBA)

    If the macros are independent try another macro in which these macros are embedded

    Please Login or Register  to view this content.
    I could not test this.

  3. #3
    Registered User
    Join Date
    06-17-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Combine 2 functions into 1 macro (VBA)

    Thanks, ill try it and let you know...
    Tried it but it does not work, it gives an error on the transpose part, strange because in standalone it works!! I did swap transpose 1 line down because it had to open the workbook first.
    Last edited by romperstomper; 09-09-2010 at 08:03 AM.

  4. #4
    Registered User
    Join Date
    06-17-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Combine 2 functions into 1 macro (VBA)

    i have attached a file...
    Attached Files Attached Files

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Combine 2 functions into 1 macro (VBA)

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-17-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Combine 2 functions into 1 macro (VBA)

    Thanks snb, clean code to do just what i want. Got an error.
    It seems to open the files 1 by 1 but then i receive an error. Only last workbook in directory got changed. Than i received a out of reach error on this line "with workbooks.open(.foundfiles(j))"

    Ill reply tomorrow cause i have a meeting.
    Last edited by romperstomper; 09-09-2010 at 08:03 AM.

  7. #7
    Registered User
    Join Date
    06-17-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Combine 2 functions into 1 macro (VBA)

    snb,

    It seems to change the open workbook only. Other workbooks open but the copy/transpose don't work .
    I would like the script to open each workbook and do the copy/transpose and close that workbook again for each workbook in the directory.

    thx

  8. #8
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Combine 2 functions into 1 macro (VBA)

    It's very naughty to cross post without mentioning it.

    http://www.ozgrid.com/forum/showthread.php?t=145990

    Can you see why? I was looking at it at Ozgrid, snb is looking at it here.

  9. #9
    Registered User
    Join Date
    06-17-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Combine 2 functions into 1 macro (VBA)

    so! is it forbidden to ask for help on different forums?.
    neither solution given solve my problem at present but i like the way i learn from you guy's.
    Oh, next time i mention that i seek help on the different forums.
    Last edited by romperstomper; 09-09-2010 at 08:03 AM.

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Combine 2 functions into 1 macro (VBA)

    I would like the script to open each workbook and do the copy/transpose and close that workbook again for each workbook in the directory.
    That's a complete new question.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-17-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Combine 2 functions into 1 macro (VBA)

    bingo, solution given works perfect except for a little error at the end of the cycle. All workbooks reflect the transpose and copy just as i wanted. Thank you very much snb.
    Last edited by romperstomper; 09-09-2010 at 08:03 AM.

  12. #12
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Combine 2 functions into 1 macro (VBA)

    so! is it forbidden to ask for help on different forums?.
    No, it is not forbidden but if you read the rules you'll see it asks that you mention you have done this.

    You had two of us spending time on this question - had I not known it had been solved here I would have merrily carried on at Ozgrid wasting my time.

  13. #13
    Registered User
    Join Date
    06-17-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Combine 2 functions into 1 macro (VBA)

    I failed to read the rules thats true, yet i did learn from your samples so it was sure not waisting time from your part. next time i mention posting a question on diff; boards/forums.
    Last edited by romperstomper; 09-09-2010 at 08:02 AM.

  14. #14
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: [solved]Combine 2 functions into 1 macro (VBA)

    That's fine. I don't want to come across as some whingeing old git. Glad you got a solution, I don't think I interpreted your question quite right as it happens.

  15. #15
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: [solved]Combine 2 functions into 1 macro (VBA)

    dversa,
    Please don't quote entire posts every time you reply to them - it serves no purpose, unless the post is not the one immediately above your reply, or if you wish to address a particular part of that post. Use the Reply button instead.
    Remember what the dormouse said
    Feed your head

+ 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