+ Reply to Thread
Results 1 to 11 of 11

Overwrite or append data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    811

    Overwrite or append data

    I have solved half the problem through help on this forum when data is appended to an existing data array. The second part - overwriting the record if it already exists - has me beaten. I have attached an example, and grateful for any help.
    Attached Files Attached Files

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Overwrite or append data

    Hello BRISBANEBOB,

    It would be of great help if you Could Post the Code you have for your sample Workbook which is totally stripped of all Code. That would enable us to approach your issue from the same "Page", without Coding any conflicts.

    Thank you.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Overwrite or append data

    You may try something like this....
    Sub CopyToDataArray()
    Dim sws As Worksheet, dws As Worksheet
    Dim rng As Range
    Dim r As Long
    Dim wht
    Set sws = Sheets("DataEntry")
    Set dws = Sheets("DataArray")
    wht = sws.Range("R8").Value
    sws.Range("C8:O8").Copy
    With dws.Range("Q:Q")
       Set rng = .Find(what:=wht, LookIn:=xlValues, LookAt:=xlWhole)
       If Not rng Is Nothing Then
          r = rng.Row
       Else
          r = dws.Cells(Rows.Count, 2).End(xlUp).Row + 1
       End If
    End With
    dws.Range("B" & r).PasteSpecial xlPasteAll
    dws.Range("Q" & r).FormulaR1C1 = "=RC[-14]&RC[-12]&RC[-9]&RC[-10]"
    End Sub
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Overwrite or append data

    Post duplicated, and deleted.

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Overwrite or append data

    @ sktneer,

    Nice work!

    Before End Sub, I would add:
    Application.CutCopyMode = False
    Maybe also adding ScreenUpdating to False and True.

    Kind Regards.

  6. #6
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    811

    Re: Overwrite or append data

    That is genius! I wouldn't have got it in a thousand years. Thanks, rep added

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Overwrite or append data

    Hi BRISBANEBOB,

    You are welcome, glad sktneer could come to your rescue, and him not minding me contributing a bit.

    Regards.

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Overwrite or append data

    @Winon
    Thanks for the appreciation.
    And yes you are correct. Those changes make the code perfect. I forgot to add those lines. Thanks for pointing that out.

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Overwrite or append data

    Hi BRISBANEBOB,

    Re your Message,

    I am battling to get one last part to work. At the moment the system will append a new record or ignore it as the record already exists. How do I get it to recognise that if one of the cells in the sheet has TRUE, it means the record should not be overwritten and ignored, but if the cell reads FALSE, the record should be overwritten? I've tried a number of tacks and all have failed! Any advice you have would be much appreciated.
    It is difficult to elaborate on how you should do what where, to try and get you to solve your issue, hence the attached sample Workbook for you perusal.

    Regards.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    811

    Re: Overwrite or append data

    Hi Minon

    Somehow I missed your additional help - only found it this morning.

    Thanks for the explanation on how it works - it's all helping me to get to grips with my awful ability (inability) to write code.

  11. #11
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Overwrite or append data

    Hello BRISBANEBOB,

    Thank you for the feedback, and also for adding to my Reputation. Much appreciated!

    You are welcome, glad I could help.

    Regards.

+ 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 split new data into multiple tabs but not overwrite existing data
    By amo899115 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-11-2016, 01:42 PM
  2. [SOLVED] append data only if date is different, otherwise overwrite
    By roothog in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2015, 05:06 PM
  3. How to code an overwrite or append via radio button
    By dovermac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2014, 12:03 PM
  4. [SOLVED] Append A Prefix String to Current Filename and Overwrite
    By sanjeevpandey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2013, 11:12 AM
  5. [SOLVED] Macro with "save as" --- Need excel to overwrite a file without a prompt to overwrite
    By tsmith1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2012, 10:54 AM
  6. Prevent data cell overwrite but allow blank cell overwrite
    By Squasher in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2011, 09:24 AM
  7. [SOLVED] Overwrite instead of append on publish
    By KLEBESTIFT in forum Excel General
    Replies: 0
    Last Post: 05-11-2006, 12:30 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