ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   Private sub (https://www.excelbanter.com/new-users-excel/20817-private-sub.html)

Mark

Private sub
 
I have the following running under a command button.
it works once and then the next time an error appears on
the following line under Sh

For Each Sh In wb.Worksheets



Private Sub CommandButton1_Click()
Dim wb As Workbook
'copy all sheets
Worksheets.Copy
Set wb = ActiveWorkbook
Application.DisplayAlerts = False
'delete the sheets you want
wb.Sheets(Array("Suspense", "RCA exc RIM", "Operations
summary", "RCA incl RIM", "First Qtr", "Second
Qtr", "Third Qtr", "Fourth Qtr")).Delete
Application.DisplayAlerts = True

For Each Sh In wb.Worksheets
Sh.Columns("A:B").EntireColumn.Delete
Next
End Sub

Any help please

Mark

Mark

Sorry got it working.
i had it running under option explicit, when i removed
this it works fine.

mark
-----Original Message-----
I have the following running under a command button.
it works once and then the next time an error appears on
the following line under Sh

For Each Sh In wb.Worksheets



Private Sub CommandButton1_Click()
Dim wb As Workbook
'copy all sheets
Worksheets.Copy
Set wb = ActiveWorkbook
Application.DisplayAlerts = False
'delete the sheets you want
wb.Sheets(Array("Suspense", "RCA exc RIM", "Operations
summary", "RCA incl RIM", "First Qtr", "Second
Qtr", "Third Qtr", "Fourth Qtr")).Delete
Application.DisplayAlerts = True

For Each Sh In wb.Worksheets
Sh.Columns("A:B").EntireColumn.Delete
Next
End Sub

Any help please

Mark
.


JE McGimpsey

Removing Option Explicit should never fix the problem you posted. It
affects only the compiling of the project - if it ran once, then it
compiled OK.



In article ,
"Mark" wrote:

Sorry got it working.
i had it running under option explicit, when i removed
this it works fine.


mark

I have this worksheet running in a database on lotus
notes and i have had problems with this in the past for
example. when i set up a workbook it work great however
when i move it to the shared database problems start to
occur. i have assumed from this that it must be the lotus
notes database.

thanks for your help

mark.


-----Original Message-----
Removing Option Explicit should never fix the problem

you posted. It
affects only the compiling of the project - if it ran

once, then it
compiled OK.



In article ,
"Mark" wrote:

Sorry got it working.
i had it running under option explicit, when i removed
this it works fine.

.



All times are GMT +1. The time now is 03:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com