+ Reply to Thread
Results 1 to 3 of 3

Macro - Delete Sheets in Workbook and Rename Sheet per Cell Reference

Hybrid View

  1. #1
    Registered User
    Join Date
    12-22-2020
    Location
    Tampa,FL
    MS-Off Ver
    2019
    Posts
    70

    Question Macro - Delete Sheets in Workbook and Rename Sheet per Cell Reference

    Hello Everyone,

    I am trying to create a macro that will Delete all sheets attached and only keep one sheet (Detailed Invoice 0).


    Then I would like to rename the sheet based upon two cell references (A2-F2)

    I have attached an example and also a final showing what I would like with a macro.
    Attached Files Attached Files
    Last edited by cvici; 02-19-2021 at 06:18 PM.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,016

    Re: Macro - Delete Sheets in Workbook and Rename Sheet per Cell Reference

    Try this:
    Option Explicit
    
    Sub BSB()
        Dim ws As Worksheet
        
        Application.DisplayAlerts = False
        For Each ws In ThisWorkbook.Sheets
            With ws
                If .Name <> "Detailed Invoice 0" Then
                    .Delete
                Else
                    .Name = .Range("A2") & "-" & .Range("F2")
                End If
            End With
        Next
        Application.DisplayAlerts = True
    End Sub
    BSB

  3. #3
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Macro - Delete Sheets in Workbook and Rename Sheet per Cell Reference

    Or maybe
    Sub test()
        Application.DisplayAlerts = False
        Sheets(Array("Invoice Cover Page", "Valuations", "Transactions", "Surcharges")).Delete
        Application.DisplayAlerts = True
        With ActiveSheet
            .Name = .Range("A2") & "-" & .Range("F2")
        End With
    End Sub

+ 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] macro to rename all sheets in workbook as criteria cells A2 of each sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-13-2019, 04:44 PM
  2. Replies: 0
    Last Post: 02-06-2015, 04:50 PM
  3. [SOLVED] Macro to delete sheets in a workbook if sheet does not contain specific word
    By elgato74 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-26-2014, 02:08 PM
  4. [SOLVED] Code to create new sheet and rename, regardless of any other sheets in workbook
    By csh8428 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-19-2012, 02:22 PM
  5. Replies: 0
    Last Post: 04-28-2012, 06:06 PM
  6. Code to delete sheets and rename sheets in a protected workbook?
    By leaning in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-07-2011, 03:02 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