Deleting of names

K

kurt

Hello All

When I run my progran I use names the macro itself append number when
it is runned (xxxx); why??
How do I delete all theese names "Query_from_MS_Access_Database_xxxx"

Sub DeleteNames()
Dim sh As Workbook
On Error Resume Next

For t = 1 To 3500
x = "Query_from_MS_Access_Database_" & t
sh.Names(x).Delete
Next t

End Sub

This code does not work properly even if I change workbook to worksheet
and run i in the sheet or the workbook
Please help???
regards Kurt
 
G

Gary Keramidas

do you want to delete queries?
would this work for you?
got this here in the ng.

sub remove()
Dim MyQT As QueryTable
Dim i As Long
Dim j As Long
Dim sheet As Worksheet

For Each sheet In Sheets
i = sheet.Index
For j = Worksheets(i).QueryTables.Count To 1 Step -1
Set MyQT = Worksheets(i).QueryTables(j)
MyQT.Delete
Next
Next
end sub
 
K

kurt

Helo Gary
Thank you for replying
I am not sure what you mean, but when I look in INSERT NAMES DEFINE I
have a lot (2000) of names Called "Query_from_MS_Access_Database_xxxx"
where xxxx is a number and they refer to "!#REF!"
I want to get rid of theese.


regards

Kurt



Gary Keramidas skrev:
 
B

Bob Phillips

This works for me

Sub DeleteNames()
Dim nme As Name

For Each nme In ActiveWorkbook.Names
If Left(nme.Name, 30) = "Query_from_MS_Access_Database_" Then _
nme.Delete
Next nme

End Sub



--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top