Results 1 to 9 of 9

Renaming a sheet and file name

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,689

    Renaming a sheet and file name

    Hi,

    I have two macros that do the same task but i need to amend them both slightly and I require some help please...

    In the code:
    Sub Splitter(): Dim PC As Object, TB As String, UR As Range, P As String
    Dim ws As Worksheet, wb As Workbook, n As Long, BN As String, K
    Set PC = CreateObject("Scripting.Dictionary")
    Set ws = Sheets("Data"): Set UR = ws.UsedRange: n = 2
    TB = "-TrialBalance-062018"
    P = ws.Parent.Path 'Enter the Path for the folder where you want the Output
    Do Until ws.Cells(n, 2) = "": BN = Trim(ws.Cells(n, 2))
    If Not PC.Exists(BN) Then PC.Item(BN) = n
    n = n + 1: Loop: K = PC.Keys()
    For n = 0 To UBound(K): BN = K(n) & TB & " " & ".XLSX"
    UR.AutoFilter Field:=2, Criteria1:=K(n)
        Set wb = Workbooks.Add
    UR.SpecialCells(xlCellTypeVisible).Copy wb.Sheets(1).Range("A1")
    wb.Sheets(1).Columns("A:D").Delete: wb.Sheets(1).Columns.AutoFit
      wb.SaveAs P & "\" & BN: wb.Close
    UR.AutoFilter
    Next n
    End Sub
    The newly created files have an additional space which I need to remove. e.g. "1010220-TrialBalance-062018 .XLS" how do I remove this?

    In both codes (Splitter and Preparefiles) new sheets are created called "Sheet1". Is there any way I can change this to "Trial Balance"? I havent included the 2nd code but its within the workbook.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Printing single sheet to .pdf then embedding the file. (renaming OLEObject?)
    By Canuckle777 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2013, 12:56 PM
  2. [SOLVED] Renaming File Name
    By wfm007 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-21-2013, 12:52 PM
  3. Renaming the file name (or part of the file name) from a list
    By bbottjen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-02-2012, 08:30 PM
  4. Writing a file’s name (or renaming it ) based on existing excel sheet data
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-30-2012, 08:11 PM
  5. Replies: 15
    Last Post: 08-27-2012, 10:13 AM
  6. Replies: 4
    Last Post: 03-09-2011, 05:25 PM
  7. Renaming a file
    By boylejob in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-27-2007, 07:47 PM
  8. [SOLVED] Renaming File
    By Arjun Dutta in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2006, 12:50 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