+ Reply to Thread
Results 1 to 5 of 5

VBA macro, including Vlookup to table, and then copy/paste/fill for the remainder of data

  1. #1
    Registered User
    Join Date
    11-07-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Question VBA macro, including Vlookup to table, and then copy/paste/fill for the remainder of data

    Hello again !

    I am about to ask for help with something, and I think that it is probably fairly easy for someone with a bit of VBA knowledge....but I don't want to assume anything. I'm guessing that asking for complete code is kind of viewed as a bit lazy, but I'm hoping that I can learn from this, and be able to do it more myself in the future.

    Here is what this macro needs to do:

    The Setup: There are two workbook opened. Workbook#1 has the data listed in a table, and is updated every so often. Workbook#2 is where all the crunching is done at.... and so the data needs to be transferred from Workbook#1 to #2, each time it is opened, because new data will have been added to Workbook#1 while the workbooks were closed. There is a date and time stamp that is unique to each row of data...and by multiplying them together, it gives a unique ID# for each row of data(and that Unique ID is put into another column(c) next to the date and time columns(A and B) ).

    So, using that lookup number I can manually do a vlookup for the last row of data in Workbook#2(where the prior days work had left off at),(from the first empty row below it(**actually I'm not sure if that's possible?) ) and thus copy over that next row of data from WB#1. To follow up transferring over the rest of the data, I assume it would be best to copy and paste it(or fill, or however it is said I this case) from WB#1 rather than use vlookup, ( in order to save resources(?).
    In any event, the goal is to use a vba macro to do that work . ( the macro recorder would work for the copying part, but because of the vlookup, I'm not sure how to accomplish that with a recorder. ??? Thus, I come to here for advice on VBA code !

    So, to recap... it needs to:
    * locate the last row of data in WB#2 then...
    * vlookup based on column C in WB#2 , and a separate table in WB#1(where the new data is). ( Im not sure how that would work because it has to look up the previous row, but vlookup returns the data from only the same row, right?)
    * ....in this example code we can transfer over just one column, but in my code there will be several columns to transfer over.
    * finally , copy /paste, (or set cells equal to), for the rest of the data from the table (in WB#1) to WB#2, w/each new row, until all the data is transferred.
    *I suppose it could execute either by push button, or as soon as the workbook is open....although I think the former might be better, just in case there is a problem with opening both workbooks.

    Well, there it is. Again , thank you for your time ! I really appreciate the boost to get me started in learning VBA better.
    Last edited by auspicium; 12-09-2013 at 09:34 PM.

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: VBA macro, including Vlookup to table, and then copy/paste/fill for the remainder of d

    it is better to use the match() and the indirect() functions
    the macro can be set to every time it is opened via the developer options

  3. #3
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: VBA macro, including Vlookup to table, and then copy/paste/fill for the remainder of d

    Hi Auspicium

    Take a look at the attached sheet. (You'll need to change a few things to accommodate the fact that my test data is completely different from your real data, but I think those changes are pretty self-evident.

    Here's the gist of the code. One thing I did add was logging each transfer, with the Date & Time fields, and the Source and Destination Rows. That way you can simnply read from that (one record) log where to start the next time.

    Please Login or Register  to view this content.
    HTH

    Tony

  4. #4
    Registered User
    Join Date
    11-07-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA macro, including Vlookup to table, and then copy/paste/fill for the remainder of d

    tfurnivall(or Tony, if I may)....

    Thank you very much for going through all of that. I didn't expect it to be quite so long....but there is more to learn, so that's good!

    I'll be going over it for the next couple days. Thanks again.

  5. #5
    Registered User
    Join Date
    11-07-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA macro, including Vlookup to table, and then copy/paste/fill for the remainder of d

    rcm,
    could you please explain why it is better to use "match" and "indirect"? ...I've actually never used "indirect".

    Thank you also !

+ 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. Macro to Copy Pivot Table and Paste a Regular Data Table in the Same Position
    By webfeet2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2013, 06:34 AM
  2. Copy paste multiple sheets including pivot table formats
    By Fursmanm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-29-2012, 09:14 AM
  3. to fill in the blanks on a Pivot table without using copy and paste
    By oasalako1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-13-2012, 01:51 PM
  4. Replies: 0
    Last Post: 08-20-2010, 09:01 AM
  5. Copy & Paste data INCLUDING hidden cells? (Excel 2003)
    By EI-ALEX in forum Excel General
    Replies: 2
    Last Post: 08-09-2010, 03:52 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