delete worksheets if cell value...

Joxu

New Member
Joined
Nov 19, 2009
Messages
21
Hi.

Sorry for long story... and rally english :-)

I try to create next one.
When opening Excel file and if macros are disabled, user get message " let me run". All anothers worksheets are then very hidden.
If user are enabled macros then he will see several worksheets, exception those what are setted xlsheetveryhidden.
but, before that I read with code environ username and application organization name. That text values will stay on worksheet "environ", cells A2 and A3. From those cells I take with function left result to cells C2 and C3. Wanted results stays in E2 and E3. On cells F2 and F3, I use simple if function to check if answers are similar as I wanted. If not then F5 have 0.
So far it is easy. But when worksheet environ cell F5 are zero I want to delete all worksheets on that file. I have tried many different codes but my skills seems to be too poor.
All those I want to run without any display alerts and without screenupdate flasing. And run those from Private sub workbook open.
Later on when its work it will be saved as template.
was this too long question??
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi.

Sorry for long story... and rally english :-)

I try to create next one.
When opening Excel file and if macros are disabled, user get message " let me run". All anothers worksheets are then very hidden.
If user are enabled macros then he will see several worksheets, exception those what are setted xlsheetveryhidden.
but, before that I read with code environ username and application organization name. That text values will stay on worksheet "environ", cells A2 and A3. From those cells I take with function left result to cells C2 and C3. Wanted results stays in E2 and E3. On cells F2 and F3, I use simple if function to check if answers are similar as I wanted. If not then F5 have 0.
So far it is easy. But when worksheet environ cell F5 are zero I want to delete all worksheets on that file. I have tried many different codes but my skills seems to be too poor.
All those I want to run without any display alerts and without screenupdate flasing. And run those from Private sub workbook open.
Later on when its work it will be saved as template.
was this too long question??

This almost work
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
Dim myCount 'This line of code is optional
Dim i 'This line of code is optional
On Error Resume Next
myCount = Application.Sheets.Count
Sheets(1).Visible = True
Range("A1").Select
For i = 2 To myCount
Sheets(i).Visible = xlVeryHidden
If i = myCount Then
End If
Next i
ActiveWorkbook.Save
Application.ScreenUpdating = True

End Sub
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Worksheets("environ").Activate
Worksheets("environ").Range("a2").Value = Environ("username")
Worksheets("environ").Range("a3").Value = Application.OrganizationName
Dim ws As Worksheet

If Range("f5").Value = 0 Then

Sheets("environ").Activate
Columns("a:bz").Select
Cells.Clear
Range("a1").Select
Application.DisplayAlerts = False
Sheets("X").Delete
Sheets("XX").Delete
Sheets("XXX").Delete
Sheets("XXXX").Delete
Sheets("pricebook").Delete

Application.DisplayAlerts = True
Else

'For Each ws In Worksheets
Sheets("XX").Visible



If ws.Name = "pricebook" Then
ws.Visible = Visible
End If

Next


Sheets("environ").Activate
ActiveWindow.SelectedSheets.Delete

Application.ScreenUpdating = True

End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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
Back
Top