+ Reply to Thread
Results 1 to 7 of 7

Refresh without deleting

Hybrid View

  1. #1
    Registered User
    Join Date
    09-05-2022
    Location
    Paris, France
    MS-Off Ver
    2016
    Posts
    85

    Refresh without deleting

    I have in my excel worksheet a macro that gets from a page 2 values from different columns and concats them together in another ****.

    this is the code i use :
    Sub oui(wsName1$, wsName2$)
    Dim Tbl As ListObject, C As Range, Vec, Tmp
    Dim ws1 As Worksheet, ws2 As Worksheet
    
    Set ws1 = ThisWorkbook.Worksheets(wsName1)
    Set ws2 = ThisWorkbook.Worksheets(wsName2)
    
        Set Tbl = ws1.Range("A1").ListObject
        If Tbl.ListRows.Count > 0 Then Tbl.DataBodyRange.Delete
        With ws2
            For Each C In .Range("C2", .Range("C1").End(xlDown))
                Vec = Split(C.Value, ",")
                For Each Tmp In Vec
                    Tbl.ListRows.Add.Range.Columns(1) = WorksheetFunction.Trim(Tmp) & " / " & C(, -1)
                Next
            Next
        End With
    End Sub
    
    
    'usage
    Sub Test()
    Call oui("Feuil2", "Feuil1")
    End Sub
    The problem i have, as you can see in my file (further down), is that if i already add a couple and write new ones it will delete the previous one.

    In my sheet, Jane / Football is already shown and commented and if i click on the button to add the new ones it will delete what i add previously.

    How can i fix this ? thank you

    here is my file : macroproblem.xlsm

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2501
    Posts
    1,440

    Re: Refresh without deleting

    Try it as below:
    Sub oui(wsName1$, wsName2$)
    Dim Tbl As ListObject, C As Range, Vec, Tmp
    Dim ws1 As Worksheet, ws2 As Worksheet
    
    Set ws1 = ThisWorkbook.Worksheets(wsName1)
    Set ws2 = ThisWorkbook.Worksheets(wsName2)
    
        Set Tbl = ws1.Range("A1").ListObject
        'If Tbl.ListRows.Count > 0 Then Tbl.DataBodyRange.Delete
        With ws2
            For Each C In .Range("C2", .Range("C1").End(xlDown))
                Vec = Split(C.Value, ",")
                For Each Tmp In Vec
                    Tbl.ListRows.Add.Range.Columns(1) = WorksheetFunction.Trim(Tmp) & " / " & C(, -1)
                Next
            Next
        End With
    End Sub
    If things don't change they stay the same

  3. #3
    Registered User
    Join Date
    09-05-2022
    Location
    Paris, France
    MS-Off Ver
    2016
    Posts
    85

    Re: Refresh without deleting

    Yes this is what i tried before. It keeps the one i already wrote but the problem is that it re-adds it so i have it twice. I don't know if it is possible to fix and add only the new one ?

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2501
    Posts
    1,440

    Re: Refresh without deleting

    Do you hope to build on the data in'Feuil1' and have it process new entries OR do you change the data completely in 'Feuil1' each time before you run it?

  5. #5
    Registered User
    Join Date
    09-05-2022
    Location
    Paris, France
    MS-Off Ver
    2016
    Posts
    85

    Re: Refresh without deleting

    I could write Jane / 001 / Football on 'Feuil1' then process to click on the button to display 'Jane / Football' on 'Feuil2' and then later come back to 'Feuil1' to add more data (without deleting Jane's row)

  6. #6
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2501
    Posts
    1,440

    Re: Refresh without deleting

    One option could be to remove duplicates from the final table after the macro has run:
    Sub oui(wsName1$, wsName2$)
    Dim Tbl As ListObject, C As Range, Vec, Tmp
    Dim ws1 As Worksheet, ws2 As Worksheet
    
    Set ws1 = ThisWorkbook.Worksheets(wsName1)
    Set ws2 = ThisWorkbook.Worksheets(wsName2)
    
        Set Tbl = ws1.Range("A1").ListObject
        With ws2
            For Each C In .Range("C2", .Range("C1").End(xlDown))
                Vec = Split(C.Value, ",")
                For Each Tmp In Vec
                    Tbl.ListRows.Add.Range.Columns(1) = WorksheetFunction.Trim(Tmp) & " / " & C(, -1)
                Next
            Next
        End With
        Range("Tableau2[#All]").RemoveDuplicates 1, xlYes
    End Sub

  7. #7
    Registered User
    Join Date
    09-05-2022
    Location
    Paris, France
    MS-Off Ver
    2016
    Posts
    85

    Re: Refresh without deleting

    Works perfectly thank you so much !!

+ 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. Avoid PowerQuery refresh from deleting empty columns
    By Barslund in forum Excel General
    Replies: 10
    Last Post: 01-10-2018, 04:19 AM
  2. Macro to refresh Essbase data sets, display refresh date?
    By nellaneb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-17-2014, 03:59 PM
  3. Replies: 2
    Last Post: 09-29-2013, 06:15 AM
  4. Replies: 1
    Last Post: 09-28-2013, 07:11 PM
  5. [SOLVED] Using VBA to change a pivot table filter, refresh the report and set up a refresh delay
    By Bonnister in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-18-2012, 10:43 AM
  6. Enable Auto Refresh - Wait for refresh to sinish before running a macro
    By tomlancaster in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2011, 11:52 AM
  7. Trouble deleting rows after pivot table refresh
    By JChandler22 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-02-2007, 01:42 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