PC Review


Reply
Thread Tools Rate Thread

delete sheet

 
 
ranswrt
Guest
Posts: n/a
 
      14th Jul 2008
I have a procedure to delete a sheet in a workbook. All the named cells in
that sheet gets deleted. When I use the 'F3' to paste the list of named
cells, the cells in the sheet that was deleted appear in it. Do I need to
delete the named cells before I delete the sheet?

Thanks
 
Reply With Quote
 
 
 
 
Mike H.
Guest
Posts: n/a
 
      14th Jul 2008
It looks like that is the only way to get them to disappear from the "F3"
list.

"ranswrt" wrote:

> I have a procedure to delete a sheet in a workbook. All the named cells in
> that sheet gets deleted. When I use the 'F3' to paste the list of named
> cells, the cells in the sheet that was deleted appear in it. Do I need to
> delete the named cells before I delete the sheet?
>
> Thanks

 
Reply With Quote
 
ranswrt
Guest
Posts: n/a
 
      14th Jul 2008
Is there a problem to not delete the named cells berfore a sheet is deleted?

"Mike H." wrote:

> It looks like that is the only way to get them to disappear from the "F3"
> list.
>
> "ranswrt" wrote:
>
> > I have a procedure to delete a sheet in a workbook. All the named cells in
> > that sheet gets deleted. When I use the 'F3' to paste the list of named
> > cells, the cells in the sheet that was deleted appear in it. Do I need to
> > delete the named cells before I delete the sheet?
> >
> > Thanks

 
Reply With Quote
 
Mike H.
Guest
Posts: n/a
 
      14th Jul 2008
I can not think of a single reason why there would be a problem. The named
ranges no longer appear when you hit F5, the Goto Range Key and the F3 key
seems to be the only place that "keeps" them. So I don't think it is a
problem.

"ranswrt" wrote:

> Is there a problem to not delete the named cells berfore a sheet is deleted?
>
> "Mike H." wrote:
>
> > It looks like that is the only way to get them to disappear from the "F3"
> > list.
> >
> > "ranswrt" wrote:
> >
> > > I have a procedure to delete a sheet in a workbook. All the named cells in
> > > that sheet gets deleted. When I use the 'F3' to paste the list of named
> > > cells, the cells in the sheet that was deleted appear in it. Do I need to
> > > delete the named cells before I delete the sheet?
> > >
> > > Thanks

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      14th Jul 2008
You could delete the names before or after you delete the worksheet--or you
could let those invalid names just stick around.

If you're working with names, get Jan Karel Pieterse's (with Charles
Williams and Matthew Henson) Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

You'll find it very valuable.



ranswrt wrote:
>
> I have a procedure to delete a sheet in a workbook. All the named cells in
> that sheet gets deleted. When I use the 'F3' to paste the list of named
> cells, the cells in the sheet that was deleted appear in it. Do I need to
> delete the named cells before I delete the sheet?
>
> Thanks


--

Dave Peterson
 
Reply With Quote
 
Skinman
Guest
Posts: n/a
 
      14th Jul 2008
When you create a name in a worksheet, it creates it for the workbook. That
is why is is still
there after you delete the sheet. However if you want to get rid of it you
can go to the name manager
and select it and the delete icon will become active. Click on the delete
and it is gone.
Skinman



"ranswrt" <(E-Mail Removed)> wrote in message
news:E9A7FCCD-74F3-46E0-A6C1-(E-Mail Removed)...
> Is there a problem to not delete the named cells berfore a sheet is
> deleted?
>
> "Mike H." wrote:
>
>> It looks like that is the only way to get them to disappear from the "F3"
>> list.
>>
>> "ranswrt" wrote:
>>
>> > I have a procedure to delete a sheet in a workbook. All the named
>> > cells in
>> > that sheet gets deleted. When I use the 'F3' to paste the list of
>> > named
>> > cells, the cells in the sheet that was deleted appear in it. Do I need
>> > to
>> > delete the named cells before I delete the sheet?
>> >
>> > Thanks


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      14th Jul 2008
ps.

You may want to start using local/worksheet names instead of global/workbook
names.

ranswrt wrote:
>
> I have a procedure to delete a sheet in a workbook. All the named cells in
> that sheet gets deleted. When I use the 'F3' to paste the list of named
> cells, the cells in the sheet that was deleted appear in it. Do I need to
> delete the named cells before I delete the sheet?
>
> Thanks


--

Dave Peterson
 
Reply With Quote
 
ranswrt
Guest
Posts: n/a
 
      14th Jul 2008
Thanks for your help

"Dave Peterson" wrote:

> ps.
>
> You may want to start using local/worksheet names instead of global/workbook
> names.
>
> ranswrt wrote:
> >
> > I have a procedure to delete a sheet in a workbook. All the named cells in
> > that sheet gets deleted. When I use the 'F3' to paste the list of named
> > cells, the cells in the sheet that was deleted appear in it. Do I need to
> > delete the named cells before I delete the sheet?
> >
> > Thanks

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      14th Jul 2008
You could use code like this to delete your worksheet and any Names
referencing it...

Sub DeleteSheetAndItsNames()
Dim N As Name
Dim WS As String
WS = "Sheet3"
For Each N In ThisWorkbook.Names
If Mid(Split(N.RefersTo, "!")(0), 2) = WS Then N.Delete
Next
Worksheets(WS).Delete
End Sub

Just change the worksheet name reference or, better still maybe, make it a
Variant argument to the subroutine (then you can specify the worksheet name
or number) so that your code can call it and specify the worksheet name or
number when doing so. You can then, of course, bolster it up with some error
checking.

Rick


"ranswrt" <(E-Mail Removed)> wrote in message
news:4A99B6CB-DC28-4ECB-B5E4-(E-Mail Removed)...
>I have a procedure to delete a sheet in a workbook. All the named cells in
> that sheet gets deleted. When I use the 'F3' to paste the list of named
> cells, the cells in the sheet that was deleted appear in it. Do I need to
> delete the named cells before I delete the sheet?
>
> Thanks


 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      14th Jul 2008
Well, actually, if you changed it to a Variant argument, you would have to
adapt the If-Then statement to account for that. Something like this
maybe...

Sub DeleteSheetAndItsNames(WS As Variant)
Dim N As Name
Dim S As Worksheet
If WS Like String(Len(WS), "#") Then
If WS <= Worksheets.Count Then
WS = Worksheets(WS).Name
End If
End If
For Each S In Worksheets
If S.Name = WS Then
For Each N In ThisWorkbook.Names
If Mid(Split(N.RefersTo, "!")(0), 2) = WS Then N.Delete
Next
Worksheets(WS).Delete
Exit Sub
End If
Next
MsgBox "No such worksheet!", vbCritical, "No Such Worksheet"
Err.Raise 1111, , "No such worksheet!"
End Sub

I provided a trappable error that can be caught by your calling code. For
example...

Sub Test()
On Error GoTo Whoops
DeleteSheetAndItsNames "SheetX"
Exit Sub
Whoops:
Debug.Print Err.Number, Err.Description
End Sub

Rick


"Rick Rothstein (MVP - VB)" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> You could use code like this to delete your worksheet and any Names
> referencing it...
>
> Sub DeleteSheetAndItsNames()
> Dim N As Name
> Dim WS As String
> WS = "Sheet3"
> For Each N In ThisWorkbook.Names
> If Mid(Split(N.RefersTo, "!")(0), 2) = WS Then N.Delete
> Next
> Worksheets(WS).Delete
> End Sub
>
> Just change the worksheet name reference or, better still maybe, make it a
> Variant argument to the subroutine (then you can specify the worksheet
> name or number) so that your code can call it and specify the worksheet
> name or number when doing so. You can then, of course, bolster it up with
> some error checking.
>
> Rick
>
>
> "ranswrt" <(E-Mail Removed)> wrote in message
> news:4A99B6CB-DC28-4ECB-B5E4-(E-Mail Removed)...
>>I have a procedure to delete a sheet in a workbook. All the named cells
>>in
>> that sheet gets deleted. When I use the 'F3' to paste the list of named
>> cells, the cells in the sheet that was deleted appear in it. Do I need
>> to
>> delete the named cells before I delete the sheet?
>>
>> Thanks

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete ROW on Sheet#1 corupts data on Sheet#2 Duane Microsoft Excel Worksheet Functions 4 11th Feb 2010 07:53 PM
Delete values in sheet 2 that arre found in sheet 1 np Microsoft Excel Misc 1 10th Dec 2009 07:21 PM
Re: Delete Rows from sheet 1 from values in sheet 2 Patrick Molloy Microsoft Excel Programming 0 26th Nov 2009 04:13 PM
Delete cells in Excel 2007 give a pop up: delete entire sheet row? frogman7 Microsoft Excel Discussion 1 15th Jan 2008 08:58 PM
Delete data in a linked Excel sheet using Access code or seql delete Rocky Microsoft Access External Data 9 26th Jun 2005 12:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:15 PM.