+ Reply to Thread
Results 1 to 10 of 10

Update worksheet from source with VBA, but not updating

  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    Poland
    MS-Off Ver
    Excel 365 64bits
    Posts
    46

    Update worksheet from source with VBA, but not updating

    Dear All,

    hope you are doing fine.

    i am having a big worksheet holding parts.
    from time to time i need to make an update.
    for last years i was doing it manually, which took me approx. 3-4h.

    this year i decided to write macro which will import only NEW parts from the source worksheet.

    i looked over Internet, found code using Find method.
    but it does not work. in theory it should be very simple code.

    what i expect from the code:
    - initially code checks if the part exists already in the DataBase Parts
    - if not, then should be added at the end of the DataBase Parts from the source worksheet.

    below code does not update the content, beside that returns the error "Object Variable or with block variable not set".

    can you please help me here? thanks in advance.


    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Update worksheet from source with VBA, but not updating

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    01-22-2013
    Location
    Poland
    MS-Off Ver
    Excel 365 64bits
    Posts
    46

    Re: Update worksheet from source with VBA, but not updating

    Hi AlphaFrog,

    thank you for quick feedback.

    I don't know why but your code returns value from last row only...
    even i cleaned completely the DataBase Parts so it is empty and all rows from Source should be copied...

    do you have idea?

    btw. maybe i should add one info, wsS.Cells(n, 4) holds either a six digit code i.e. 378432 or a string R44-1011-01.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Update worksheet from source with VBA, but not updating

    You both forgot the underscore in the variable name Last_RowD.

    Please Login or Register  to view this content.
    But a loop like this will take a long time on a large worksheet.

    Try this instead.(took 0.2 sec for 5000 lines)

    Please Login or Register  to view this content.
    Last edited by bakerman2; 08-09-2021 at 01:13 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Registered User
    Join Date
    01-22-2013
    Location
    Poland
    MS-Off Ver
    Excel 365 64bits
    Posts
    46

    Re: Update worksheet from source with VBA, but not updating

    Dear bakerman2,

    thanks. yes it is extremely fast macro.
    looking for your code i have to say that i am far from VBA...

    got one question, the source beside the unique code, holds also parameters of the part.
    how to use your code to get other parameters to the destination worksheet?

    i.e.


    Parameters Source Destination
    Length Column E Column B
    having approx. 70 different parameters describing the unique part.

    optionally i can use match and index via formulas but it will be slow like hell.

    thanks for the hint.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Update worksheet from source with VBA, but not updating

    Can you post an example workbook with Source & Destination sheet, including headers and a few parts so as we can see which value from Source

    has to be copied to which column on Destination.

    We could then create Array in memory and write to Destination sheet in 1 go.

  7. #7
    Registered User
    Join Date
    01-22-2013
    Location
    Poland
    MS-Off Ver
    Excel 365 64bits
    Posts
    46

    Re: Update worksheet from source with VBA, but not updating

    please find the file.

    the problem i see (or maybe it is not a problem) there is no same order in both worksheets.
    and this cannot be changed...

    thank you for your time!
    Attached Files Attached Files

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Update worksheet from source with VBA, but not updating

    Based on your example file.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-22-2013
    Location
    Poland
    MS-Off Ver
    Excel 365 64bits
    Posts
    46

    Re: Update worksheet from source with VBA, but not updating

    Dear bakerman2,

    thank you. it works really fast and in the way i expected.

    i did not know it before. i will try to understand it...


    i owe you a beer or should sponsor a coffee

    have a good day.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Update worksheet from source with VBA, but not updating

    Let's stick with the coffee.

    You're very welcome and thanks for rep+.

    If you have any questions regarding the code just give a shout.

+ 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. Replies: 0
    Last Post: 02-13-2020, 07:05 PM
  2. Copy Source Worksheet to Target Worksheet updating Named Ranges (with Source Ranges)
    By CRIMEDOG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-01-2018, 07:19 AM
  3. Replies: 2
    Last Post: 09-28-2016, 02:09 PM
  4. Replies: 0
    Last Post: 07-21-2015, 02:35 AM
  5. [SOLVED] Update DropDown selected value after updating source
    By L1va4ka in forum Excel General
    Replies: 8
    Last Post: 02-25-2014, 05:46 AM
  6. [SOLVED] Update source data for multiple pivot tables on same worksheet
    By Platinum3x in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 03-19-2013, 12:11 AM
  7. Replies: 4
    Last Post: 10-27-2006, 02:32 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