+ Reply to Thread
Results 1 to 12 of 12

Trying to copy range of values from one WB to another by finding date in list

  1. #1
    Registered User
    Join Date
    03-30-2020
    Location
    Houston, TX
    MS-Off Ver
    365
    Posts
    12

    Trying to copy range of values from one WB to another by finding date in list

    I've got a mess here that I'm struggling through. I am trying to copy WB(Book1) Sheet(Net) Range(E7:E9) to WB(Book2) Sheet(Sheet1) corresponding col's C,D, E based on matching date from Book1 to Book2 range of dates col B (1/1(B4) to 12/31(B369)). So very stuck. Any help greatly apreciated! What I have so far:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by robxl; 04-09-2020 at 11:48 AM. Reason: Add code tags

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Trying to copy range of values from one WB to another by finding date in list


    So without code tags (so easy via the icon !) according to the forum rules - a must read ! -
    I just can advise to use the easy fliter or advanced filter …

  3. #3
    Registered User
    Join Date
    03-30-2020
    Location
    Houston, TX
    MS-Off Ver
    365
    Posts
    12

    Re: Trying to copy range of values from one WB to another by finding date in list

    Thx Marc, will do the code tags, thought that was the commenting I did in code!

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Trying to copy range of values from one WB to another by finding date in list


    Thanks ! Now helpers can take a glance to your need …

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this ‼


    According to your attachmment a VBA beginner starter demonstration where
    you must update the file path variable if Book2 is not in the same folder than Book1 :

    PHP Code: 
    Sub Demo1()
        
    Dim F$, Rg As Range
            F 
    ThisWorkbook.Path Application.PathSeparator "Book2.xlsm"
            
    If Dir(F) = "" Then Beep: Exit Sub
            Application
    .ScreenUpdating False
        With Workbooks
    .Open(F).ActiveSheet
            Set Rg 
    = .Range("B3", .[B3].End(xlDown)).Find(Sheet2.[B4].Value, , xlFormulas)
            If 
    Not Rg Is Nothing Then Rg.Columns("B:D") = Sheet2.[TRANSPOSE(E7:E9)]
           .
    Parent.Close Not Rg Is Nothing
        End With
            Application
    .ScreenUpdating True
            
    If Rg Is Nothing Then MsgBox "Date not found"vbExclamation"Copy" Else Set Rg Nothing
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Registered User
    Join Date
    03-30-2020
    Location
    Houston, TX
    MS-Off Ver
    365
    Posts
    12

    Re: Trying to copy range of values from one WB to another by finding date in list

    Man that's great, it works! Thanks a million Marc!

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Trying to copy range of values from one WB to another by finding date in list


    Read the advise under the code - as the way to thanks helpers on forum - and

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

  8. #8
    Registered User
    Join Date
    03-30-2020
    Location
    Houston, TX
    MS-Off Ver
    365
    Posts
    12

    Thumbs up Re: Trying to copy range of values from one WB to another by finding date in list

    Marc, I hate to bother you again but I just had a chance today to incorporate the code into my project. The issue is the samples I provided unfortunately aren't quite the same. My sample was just numbers I entered. My actual sheets have formulas I input to get those values. So for some hours today I've been trying to get to the bottom of the prob. Simply transposing from the cells with formulas doesn't yield a value (returns "0"). I've tried several approaches with the code. I have the latest posted below. I tried defining an array and values in a range. That returned a #name error. I directly tried to transpose the cells and get the #value error. I couldn't manual transpose and get values other than "0" so I tried copy and paste special and got the values. I recorded a macro and looked at the code for this as a way to transpose the values but hit another dead end. Any insight and help is always greatly appreciated! Also saw your note and added rep.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    03-30-2020
    Location
    Houston, TX
    MS-Off Ver
    365
    Posts
    12

    Re: Trying to copy range of values from one WB to another by finding date in list

    Well I woke up this morning and reopened the project. I tried the code where I used Paste Special and it seems to work... (code below). I guess my question would now be, is this the best/most efficient method?

    Many thanks!
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb

    Posting an attachment with a different layout than the original is often not a good idea
    or you must be very confident with your Excel / VBA skills to amend any code …

    According to my demonstration and your last attachment :

    PHP Code: 
    Sub copytothroughputsMOD()
        
    Dim F$, Rg As Range
            F 
    ThisWorkbook.Path Application.PathSeparator "Throughputs.xlsm"
            
    If Dir(F) = "" Then Beep: Exit Sub
            Application
    .ScreenUpdating False
        With Workbooks
    .Open(F).Sheets(1)
               
    Set Rg = .Range("B3", .[B3].End(xlDown)).Find(Sheet11.[C2].Value, , xlFormulas)
            If 
    Not Rg Is Nothing Then Rg.Columns("B:K") = Application.Index(Sheet11.Columns(15), [{13,16,19,22,24,27,31,33,35,37}])
           .
    Parent.Close Not Rg Is Nothing
        End With
            Application
    .ScreenUpdating True
            
    If Rg Is Nothing Then MsgBox "Date not found"vbExclamation"Copy" Else Set Rg Nothing
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 04-13-2020 at 01:32 PM.

  11. #11
    Registered User
    Join Date
    03-30-2020
    Location
    Houston, TX
    MS-Off Ver
    365
    Posts
    12

    Cool Re: Trying to copy range of values from one WB to another by finding date in list

    I wouldn't say I'm that confident in VBA but I have had success in the past with amending code and if nothing else using the debugger. I either try to find examples or record macros and read through to see what is going on in the code. I greatly appreciate your help and your coding is MUCH better than a lot of examples I've seen (in general). I will use the code you've attached. I've learned a lot! Thanks again!

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Thumbs up Re: Trying to copy range of values from one WB to another by finding date in list


    Thanks for your appreciation !

    In last code, Application.Index is the worksheet function INDEX as Excel features can often help to write a code easier …

    Using the Macro Recorder is a good way to see which statements are needed for a particular task
    but after you have to clean the code removing the useless like for example the Select, Activate, …
    … as playing directly with objects is often more efficient.
    Last edited by Marc L; 04-13-2020 at 08:58 PM.

+ 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. VBA code to copy values in a range or list
    By gototcm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2019, 12:53 PM
  2. [SOLVED] VBA Copy Cells in Range if Values not in List
    By phelbin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-09-2017, 03:25 PM
  3. [SOLVED] help list unique values within a date range
    By XL. in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-12-2016, 03:14 PM
  4. HELP with Finding similar values in same date range -- Multiple Criteria
    By yessuz in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-08-2016, 04:33 AM
  5. [SOLVED] List of multiple values within a Date range
    By Quasis in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-25-2015, 04:36 AM
  6. [SOLVED] Finding unique values for a date range
    By designergav in forum Outlook Formatting & Functions
    Replies: 13
    Last Post: 05-12-2015, 06:39 AM
  7. [SOLVED] need help finding a Date range within long list
    By A shink in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-30-2005, 12:06 PM

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