+ Reply to Thread
Results 1 to 2 of 2

Unwanted accumulation of Rangr Names

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Unwanted accumulation of Rangr Names

    The following code is used to delete old data and then download a text file with new data.

    It does the job as far as the worksheet is concerned but I have found that every time the data is renewed I get two new ranges named with FileName plus an increasing number "Budget 2017_2018"1,2,3.....n
    When you delete a Range populated by a query manually you are asked whether the query should be deleted as well. I think I need some code to do this but without asking for permission. Can anyone help please?
    Sub FetchText(SheetName, FileName)
            On Error Resume Next
              With Sheets(SheetName)
                    .Range(SheetName & "_Clear").Clear
                    .Range(SheetName & "_Transpose").Clear
              End With
            On Error GoTo 0
                     FilePath = Sheets("Utilities").Range("J3").Value
                        ConnStr = "Text;" & FilePath & FileName
    
                    With Sheets(SheetName).QueryTables.Add(Connection:=ConnStr, Destination:=Range("A9"))
                         .Name = FileName
                             .FieldNames = True
                             .SavePassword = False
                         .Refresh BackgroundQuery:=False
                    End With
         
                Range(SheetName & "_Table").Copy
        
            Sheets(SheetName).Range("A28").PasteSpecial Transpose:=True
        
    End Sub

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Unwanted accumulation of Rangr Names

    Hi,

    Perhaps add
    Sheets(SheetName).Querytables(1).Delete
    at the beginning of the code?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

+ 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] Looping through directory and removing unwanted characters from the file names
    By Ravana in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2017, 01:25 PM
  2. Accumulation
    By alexmcdonald in forum Excel General
    Replies: 1
    Last Post: 12-29-2011, 08:59 AM
  3. data accumulation
    By greeneggs83 in forum Excel General
    Replies: 1
    Last Post: 03-14-2008, 08:50 AM
  4. Accumulation in Excel ???
    By martinA in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-26-2007, 03:20 AM
  5. Accumulation and #REF
    By CharlotteP in forum Excel General
    Replies: 1
    Last Post: 10-06-2006, 04:38 PM
  6. [SOLVED] Accumulation
    By Paul in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-22-2005, 07:06 PM
  7. [SOLVED] How do I remove unwanted add-in names from the XL Tools list?
    By J_J in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-22-2005, 07:06 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