+ Reply to Thread
Results 1 to 5 of 5

overwrite / clear existing data before copying

  1. #1
    Forum Contributor
    Join Date
    06-27-2014
    Location
    bristol, england
    MS-Off Ver
    excel 2007
    Posts
    264

    overwrite / clear existing data before copying

    Hi guys just another quickie, the below code I am using to copy data is fine, but I need it to either overwrite the existing data on the sheet it is pasted to or to clear the data first before copying, the starred line in the code below I have been using in different places in the code but it does not seem to work, the range of data to be cleared is at most A2:AC198, but can be only a few rows.

    scouse13


    [code]
    Private Sub CommandButton27_Click()

    'ws2.Range("A2:AC198").ClearContents***************

    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim lr As Long, x As Long, count As Long

    Set ws1 = Sheets("Records")
    Set ws2 = Sheets("WeeklyRawData")
    lr = ws1.Range("A" & Rows.count).End(xlUp).Row
    count = 2
    For x = 2 To lr
    If ws1.Cells(x, 25).Text = Me.TextBox11.Text Then

    ws1.Range(ws1.Cells(x, 1), ws1.Cells(x, 29)).Copy Destination:=ws2.Range("A" & count)
    count = count + 1
    End If
    Next x
    ws2.Select
    Sheets("WeeklySummery").Select

    Unload Me

    End Sub
    [code/]

  2. #2
    Registered User
    Join Date
    03-01-2019
    Location
    SARAJEVO
    MS-Off Ver
    2021
    Posts
    49

    Re: overwrite / clear existing data before copying

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,153

    Re: overwrite / clear existing data before copying

    Are there column headings in "A1:AC1" range ?

  4. #4
    Registered User
    Join Date
    03-01-2019
    Location
    SARAJEVO
    MS-Off Ver
    2021
    Posts
    49

    Re: overwrite / clear existing data before copying

    Or something like this:
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: overwrite / clear existing data before copying

    No code tags, no sample file? It all goes a lot faster with the auto filter or the advanced filter.

+ 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. Save As PDF And (please do not) Overwrite Existing
    By cangokturk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2016, 02:30 PM
  2. 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
  3. Deleted
    By MaxStrong in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2015, 01:50 AM
  4. Clear existing data before running another macro?
    By Tmax95 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2014, 12:42 PM
  5. Split data from Master Sheet to existing worksheets and overwrite data
    By vmwest in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-21-2013, 05:36 PM
  6. Overwrite existing data
    By kishoremcp in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-21-2012, 09:10 PM
  7. Creating a graph with existing data...clear data after save
    By Cam Neeson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-15-2006, 01:40 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