Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
cbm cbm is offline
external usenet poster
 
Posts: 13
Default WHY THIS CLOSES EXCEL IF THERE´S NO SHEET NAMED AS...???

Hi, i´ve got a problem with this command button.
It deletes sheets named Tarea+nº and Acción+nº and works perfect
when these sheets already exist, but once i´ve deleted them i-ve got
an error when pussing again the button and excel gets closed asking me
if i want to send the error report.
I´ve already tried writing on error resume next everywhere (i´m a
beginner and don´t know the properly use of this function)


ANY IDEA??? THANKS A LOT!!!!


Private Sub CommandButton12_Click()


Dim wksH As Worksheet
Dim mtr(), n


For Each wksH In Worksheets
If Left(wksH.Name, 6) = "Acción" Then
n = n + 1
ReDim Preserve mtr(1 To n)
mtr(n) = wksH.Name
End If
Next
Worksheets(mtr()).Select


Set wksH = Nothing


For Each wksH In Worksheets
If Left(wksH.Name, 5) = "Tarea" Then
n = n + 1
ReDim Preserve mtr(1 To n)
mtr(n) = wksH.Name
End If
Next
Worksheets(mtr()).Select


Set wksH = Nothing
ActiveWindow.SelectedSheets.Delete


On Error Resume Next


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default WHY THIS CLOSES EXCEL IF THERE´S NO SHEET NAMED AS...???

The problem seems to be that if you build an array of sheet names, and some
do not exist, none get selected.

Just change the code to delete them as you go

Private Sub CommandButton12_Click()

On Error Resume Next
Application.DisplayAlerts = False
For Each wksH In Worksheets
If Left(wksH.Name, 6) = "Acción" Or _
Left(wksH.Name, 5) = "Tarea" Then
wksH.Delete
End If
Next
Application.DisplayAlerts = True
On Error GoTo 0

Set wksH = Nothing

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"cbm" wrote in message
ups.com...
Hi, i´ve got a problem with this command button.
It deletes sheets named Tarea+nº and Acción+nº and works perfect
when these sheets already exist, but once i´ve deleted them i-ve got
an error when pussing again the button and excel gets closed asking me
if i want to send the error report.
I´ve already tried writing on error resume next everywhere (i´m a
beginner and don´t know the properly use of this function)


ANY IDEA??? THANKS A LOT!!!!


Private Sub CommandButton12_Click()


Dim wksH As Worksheet
Dim mtr(), n


For Each wksH In Worksheets
If Left(wksH.Name, 6) = "Acción" Then
n = n + 1
ReDim Preserve mtr(1 To n)
mtr(n) = wksH.Name
End If
Next
Worksheets(mtr()).Select


Set wksH = Nothing


For Each wksH In Worksheets
If Left(wksH.Name, 5) = "Tarea" Then
n = n + 1
ReDim Preserve mtr(1 To n)
mtr(n) = wksH.Name
End If
Next
Worksheets(mtr()).Select


Set wksH = Nothing
ActiveWindow.SelectedSheets.Delete


On Error Resume Next


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
cbm cbm is offline
external usenet poster
 
Posts: 13
Default WHY THIS CLOSES EXCEL IF THERE´S NO SHEET NAMED AS...???

THAT WORKED GREAT!!!
Thanks a lot Bob, nice job

Bob Phillips ha escrito:

The problem seems to be that if you build an array of sheet names, and some
do not exist, none get selected.

Just change the code to delete them as you go

Private Sub CommandButton12_Click()

On Error Resume Next
Application.DisplayAlerts = False
For Each wksH In Worksheets
If Left(wksH.Name, 6) = "Acción" Or _
Left(wksH.Name, 5) = "Tarea" Then
wksH.Delete
End If
Next
Application.DisplayAlerts = True
On Error GoTo 0

Set wksH = Nothing

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"cbm" wrote in message
ups.com...
Hi, i´ve got a problem with this command button.
It deletes sheets named Tarea+nº and Acción+nº and works perfect
when these sheets already exist, but once i´ve deleted them i-ve got
an error when pussing again the button and excel gets closed asking me
if i want to send the error report.
I´ve already tried writing on error resume next everywhere (i´m a
beginner and don´t know the properly use of this function)


ANY IDEA??? THANKS A LOT!!!!


Private Sub CommandButton12_Click()


Dim wksH As Worksheet
Dim mtr(), n


For Each wksH In Worksheets
If Left(wksH.Name, 6) = "Acción" Then
n = n + 1
ReDim Preserve mtr(1 To n)
mtr(n) = wksH.Name
End If
Next
Worksheets(mtr()).Select


Set wksH = Nothing


For Each wksH In Worksheets
If Left(wksH.Name, 5) = "Tarea" Then
n = n + 1
ReDim Preserve mtr(1 To n)
mtr(n) = wksH.Name
End If
Next
Worksheets(mtr()).Select


Set wksH = Nothing
ActiveWindow.SelectedSheets.Delete


On Error Resume Next


End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2002 SP3 Copy Worksheet with another sheet named range now # Brewmanz Excel Discussion (Misc queries) 0 October 1st 09 12:35 AM
Excel 2007 closes when e-mailing sheet Joka Excel Discussion (Misc queries) 0 December 16th 08 04:43 PM
when i insert word art in excel sheet excel file closes automatica marwin Excel Discussion (Misc queries) 1 April 10th 06 03:29 PM
ADO - recordset - closed excel workbook - know sheet name and cell name but no named ranges defined grahamd Excel Programming 1 October 18th 04 06:13 PM
Enabling Add-In closes current sheet S. Daum Excel Programming 1 August 21st 03 10:28 PM


All times are GMT +1. The time now is 04:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"