+ Reply to Thread
Results 1 to 15 of 15

Need help combining two codes

  1. #1
    Registered User
    Join Date
    06-27-2018
    Location
    America
    MS-Off Ver
    2007
    Posts
    30

    Need help combining two codes

    I have two codes, one that auto selects a file based on a partial title, and the other that copies and pastes.

    Please Login or Register  to view this content.
    After running the program I keep getting this message, "Run-time error 91: Object variable or with block variable not set"

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Need help combining two codes

    Hi, on what line of code does it error?

  3. #3
    Registered User
    Join Date
    06-27-2018
    Location
    America
    MS-Off Ver
    2007
    Posts
    30

    Re: Need help combining two codes

    None of the lines shows any indication there is an error, but I would imagine somewhere after the "copy range" line. The file opens automatically, but after it opens this message opens, "Run-time error 91: Object variable or with block variable not set"

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Need help combining two codes

    At a guess it's failing on this line
    Please Login or Register  to view this content.
    because the variable in blue has no value

  5. #5
    Registered User
    Join Date
    06-27-2018
    Location
    America
    MS-Off Ver
    2007
    Posts
    30

    Re: Need help combining two codes

    any recommendations to remedy this?

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Need help combining two codes

    Give it a value
    ie
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-27-2018
    Location
    America
    MS-Off Ver
    2007
    Posts
    30

    Re: Need help combining two codes

    ohhh "wsCopyFrom" shouldn't be highlighted. My code is showing only the "Set" is highlighted

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Need help combining two codes

    You have used Set a number of times in your code, which one is getting highlighted?

  9. #9
    Registered User
    Join Date
    06-27-2018
    Location
    America
    MS-Off Ver
    2007
    Posts
    30

    Re: Need help combining two codes

    The "set" from the same line: Set Fnd = wsCopyFrom.Range("5:5")

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Need help combining two codes

    Have you set wsCopyFrom before that line?

  11. #11
    Registered User
    Join Date
    06-27-2018
    Location
    America
    MS-Off Ver
    2007
    Posts
    30

    Re: Need help combining two codes

    hmmm no but for a previous code I didn't and it worked fine

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Need help combining two codes

    If you haven't assigned a worksheet to the variable, then the code will not work.

  13. #13
    Registered User
    Join Date
    06-27-2018
    Location
    America
    MS-Off Ver
    2007
    Posts
    30

    Re: Need help combining two codes

    this is my original code that allows me to open a file and select a file:

    Please Login or Register  to view this content.
    I am trying to integrate this portion of it:

    Please Login or Register  to view this content.
    Together is what my original post was about, how would one go about combing the two because I am completely lost.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Need help combining two codes

    Just add this line from
    Please Login or Register  to view this content.
    your original code to your new code to the new code after this section
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    06-27-2018
    Location
    America
    MS-Off Ver
    2007
    Posts
    30

    Re: Need help combining two codes

    omg for some reason one of the lines were missing that's why it wasn't working, thank you so much!! is there one more thing you could help me with? I have to do the same thing with 3 workbooks (in the same file), is there anyway I can make workbook one auto select 1 file and copy and paste, then workbook 2 auto select a different file then copy and paste, etc.. with one click of a button?

+ 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. Combining two codes into one
    By Aqmas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2017, 03:46 PM
  2. Call Two Codes from ComboBox
    By zplugger in forum Excel General
    Replies: 2
    Last Post: 01-24-2015, 03:02 PM
  3. Combining vba codes makes the previous codes broken !
    By MDPLUS in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-26-2013, 10:00 AM
  4. [SOLVED] Combining 2 codes?
    By bjcowen9000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2013, 02:48 PM
  5. [SOLVED] Help! combining 2 VBA codes
    By iamreese in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-29-2012, 07:24 AM
  6. combining codes
    By tweety127 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-18-2008, 06:48 PM
  7. [SOLVED] combining 2 codes
    By steve in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-18-2006, 01:15 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