Excel VBA code o hide a worksheet once copied and saved

Tony_Y

New Member
Joined
May 29, 2020
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Good evening,

Thanks to this forum and it's members I have a code which copies and saves a worksheet, naming it he value of a cell from another worksheet. I am now after taking this a little further and:

1. Hiding the newly saved sheet and
2. Unhiding and activating sheet 16.

Any help will be greatly appreciated

TIA

Tony

VBA Code

VBA Code:
Private Sub CommandButton2_Click()

   Dim shtName As String
  
   shtName = Sheet22.Range("D64").Value

   If Evaluate("isref('" & shtName & "'!A1)") Then

      MsgBox "Sheet Already Exists"

   Else
      Sheet14.Copy , Sheets(Sheets.Count)

      ActiveSheet.Name = shtName

      Sheet14.Activate

      Range("E9:E19,E38:E46,K9:K16,K38:K39").Value = 0

      MsgBox "Sheet Saved Success"

      Sheet16.Activate
     

   End If

End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
      Sheet14.Copy , Sheets(Sheets.Count)

      With ActiveSheet
         .Name = ShtName
         .Visible = xlSheetHidden
      End With
      Sheet14.Range("E9:E19,E38:E46,K9:K16,K38:K39").Value = 0

      MsgBox "Sheet Saved Success"

      Sheet16.Visible = xlSheetVisible
 

Tony_Y

New Member
Joined
May 29, 2020
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Hi Fluff,

That works great very many thanks (sorry for late reply - working).

kind regards

Tony
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,521
Messages
5,625,295
Members
416,087
Latest member
drth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top