+ Reply to Thread
Results 1 to 6 of 6

Export worksheet to another workbook without overwriting existing entries (search?)

Hybrid View

  1. #1
    Registered User
    Join Date
    10-25-2018
    Location
    PHX, Arizona
    MS-Off Ver
    O365
    Posts
    3

    Question Export worksheet to another workbook without overwriting existing entries (search?)

    I am attempting to make a thing that will take the data from the current workbook (OVC Process v1.0.3.xlsm), Sheet named "Data" and after clicking button, upload that data into another workbook "OVC Metrics.xlsx", Sheet named "Data" on a Sharepoint site. I can do the copy/past function, but I need help with the overwrite function.
    Here's what I got:

    Sub Update_All()
    
    Dim wkb1 As Workbook
    Dim sht1 As Worksheet
    Dim wkb2 As Workbook
    Dim sht2 As Worksheet
    LoadFilePath = "..........blah blah....OVC_Metrics.xlsx"
    
    Application.ScreenUpdating = False
    Application.AskToUpdateLinks = False
    
    
    Set wkb1 = ThisWorkbook
    Set wkb2 = Workbooks.Open(LoadFilePath)
    Set sht1 = wkb1.Sheets("Data")
    Set sht2 = wkb2.Sheets("Data")
    
    ' Copy Rows
    sht1.Range("A2:V1500").Copy
    
    ' Find Last Row
    lastrow = sht2.Cells(Rows.Count, "A").End(xlUp).Row
    
    ' Paste Rows
    sht2.Range("A" & lastrow + 1).PasteSpecial xlPasteAll
    
    ' Close Database
    wkb2.Close SaveChanges, Filename:=True
    MsgBox "Thanks for Uploading your Data! You're the best!"
    
    Application.ScreenUpdating = True
    
    End Sub
    If anyone could help me with this I'd be greatful.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Export worksheet to another workbook without overwriting existing entries (search?)

    If you are overwriting some of your data, then your last row variable based on column A data probably needs to be based on the actual column with the most data. So replace this


    lastrow = sht2.Cells(Rows.Count, "A").End(xlUp).Row
    with this

    lastrow = sht2.Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
    That will give you the last row with data in any column.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    10-25-2018
    Location
    PHX, Arizona
    MS-Off Ver
    O365
    Posts
    3

    Re: Export worksheet to another workbook without overwriting existing entries (search?)

    Excellent! This works locally. Now I need to figure out how to upload to sharepoint site. When I update the LoadFilePath to the sharepoint address, it gives me a "subscript out of range" error. Any tips on this?

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Export worksheet to another workbook without overwriting existing entries (search?)

    click the debug button to see which object it is that the compiler cannot find. Remember when putting it on the sharepoint drive that some of your filenames or sheet names might change, so the code has to be modified to adapt those changes.

  5. #5
    Registered User
    Join Date
    10-25-2018
    Location
    PHX, Arizona
    MS-Off Ver
    O365
    Posts
    3

    Re: Export worksheet to another workbook without overwriting existing entries (search?)

    Got it! This worked after I updated links on the wkb2

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Export worksheet to another workbook without overwriting existing entries (search?)

    Quote Originally Posted by Photomommie View Post
    Got it! This worked after I updated links on the wkb2
    thanks for the feedback, Don't forget to mark the thread as solved.
    Regards, JLG

+ 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. [SOLVED] Export data from worksheet to existing text file
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-20-2016, 07:12 AM
  2. export column A from two worsheets to one worksheet in an existing workbook
    By prestopr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-05-2013, 09:50 AM
  3. Export charts to existing workbook
    By VBA-Snail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-20-2013, 05:17 AM
  4. [SOLVED] export quety result to existing excel workbook
    By jsimha in forum Access Tables & Databases
    Replies: 4
    Last Post: 01-19-2013, 09:23 AM
  5. Search multiple workbook headers and copy column entries to another workbook
    By R3n3gad3-XtC in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-13-2012, 12:47 AM
  6. Extract existing IDs of entries repeated in a worksheet in a separate column
    By harsh2209 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-07-2011, 07:56 AM
  7. Overwriting existing data
    By KA_Analyst in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-27-2007, 10:44 AM

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