Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Excel 2003 on XP Pro
Every day I receive a text file with a single record (space delimited). I have written a macro to load that record into the next row of the worksheet, using Get External Data. All that is working fine, but in doing initial testing and debugging of the macro, I noticed that every time I bring in a new record, it creates a new external data range. I really don't need these defined data ranges, I just need the values loaded in. Really just a housekeeping issue ... several months from now, when I have 100+ rows of data, do I really want to have 100+ different external data ranges defined? Or am I obsessing about a non-issue? Is there some way to clean-up/delete the range definitions without deleting the data (cell values) itself? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
You'll find below some code which should help you ... someway. Glad to help+ '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub ShowAllNamedRanges() Dim lngNamesCount As Long Dim intPtr As Integer Dim strNamedRanges As String 'Get the nr of named ranges lngNamesCount = Application.Names.Count 'Empty the strNamedRanges text strNamedRanges = "" For intPtr = 1 To lngNamesCount strNamedRanges = strNamedRanges & vbCrLf & intPtr & " = " & Names(intPtr).Name Next intPtr MsgBox strNamedRanges End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub DeleteOneNamedRange() Dim lngNamesCount As Long Dim intPtr As Integer Dim strNamedRanges As String 'Get the nr of named ranges lngNamesCount = Application.Names.Count 'Empty the strNamedRanges text strNamedRanges = "" 'Put list of Named Ranges in strNamedRanges For intPtr = 1 To lngNamesCount strNamedRanges = strNamedRanges & vbCrLf & intPtr & " = " & Names(intPtr).Name Next intPtr Dim strPrompt, strTitle, strDefault, strConfirm As String Dim intIndexOfRangeToBeDeleted As Integer strTitle = "Delete one Named Range" strDefault = "" strPrompt = strNamedRanges & vbCrLf & "Input the index of the Named Range to be deleted ..." intIndexOfRangeToBeDeleted = Val(InputBox(strPrompt, strTitle, strDefault)) If intIndexOfRangeToBeDeleted 0 Then strTitle = strTitle & " CONFIRM..." strPrompt = "DELETE " & Names(intIndexOfRangeToBeDeleted) & vbCrLf & "<Yes or <No..." strConfirm = InputBox(strPrompt, strTitle, strDefault) If Left(strConfirm, 1) = "Y" Then Names(intIndexOfRangeToBeDeleted).Delete End If End If End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES -- Herve Hanuise http://www.affordsol.be "EdStevens" wrote: Excel 2003 on XP Pro Every day I receive a text file with a single record (space delimited). I have written a macro to load that record into the next row of the worksheet, using Get External Data. All that is working fine, but in doing initial testing and debugging of the macro, I noticed that every time I bring in a new record, it creates a new external data range. I really don't need these defined data ranges, I just need the values loaded in. Really just a housekeeping issue ... several months from now, when I have 100+ rows of data, do I really want to have 100+ different external data ranges defined? Or am I obsessing about a non-issue? Is there some way to clean-up/delete the range definitions without deleting the data (cell values) itself? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That gave me what I needed. Thanks for the help.
"affordsol" wrote: Hello, You'll find below some code which should help you ... someway. Glad to help+ '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub ShowAllNamedRanges() Dim lngNamesCount As Long Dim intPtr As Integer Dim strNamedRanges As String 'Get the nr of named ranges lngNamesCount = Application.Names.Count 'Empty the strNamedRanges text strNamedRanges = "" For intPtr = 1 To lngNamesCount strNamedRanges = strNamedRanges & vbCrLf & intPtr & " = " & Names(intPtr).Name Next intPtr MsgBox strNamedRanges End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub DeleteOneNamedRange() Dim lngNamesCount As Long Dim intPtr As Integer Dim strNamedRanges As String 'Get the nr of named ranges lngNamesCount = Application.Names.Count 'Empty the strNamedRanges text strNamedRanges = "" 'Put list of Named Ranges in strNamedRanges For intPtr = 1 To lngNamesCount strNamedRanges = strNamedRanges & vbCrLf & intPtr & " = " & Names(intPtr).Name Next intPtr Dim strPrompt, strTitle, strDefault, strConfirm As String Dim intIndexOfRangeToBeDeleted As Integer strTitle = "Delete one Named Range" strDefault = "" strPrompt = strNamedRanges & vbCrLf & "Input the index of the Named Range to be deleted ..." intIndexOfRangeToBeDeleted = Val(InputBox(strPrompt, strTitle, strDefault)) If intIndexOfRangeToBeDeleted 0 Then strTitle = strTitle & " CONFIRM..." strPrompt = "DELETE " & Names(intIndexOfRangeToBeDeleted) & vbCrLf & "<Yes or <No..." strConfirm = InputBox(strPrompt, strTitle, strDefault) If Left(strConfirm, 1) = "Y" Then Names(intIndexOfRangeToBeDeleted).Delete End If End If End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES -- Herve Hanuise http://www.affordsol.be "EdStevens" wrote: Excel 2003 on XP Pro Every day I receive a text file with a single record (space delimited). I have written a macro to load that record into the next row of the worksheet, using Get External Data. All that is working fine, but in doing initial testing and debugging of the macro, I noticed that every time I bring in a new record, it creates a new external data range. I really don't need these defined data ranges, I just need the values loaded in. Really just a housekeeping issue ... several months from now, when I have 100+ rows of data, do I really want to have 100+ different external data ranges defined? Or am I obsessing about a non-issue? Is there some way to clean-up/delete the range definitions without deleting the data (cell values) itself? |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Well, that was essentially what I needed .... ;-)
After playing around with the code you provided and seeing how it works, for my purposes I reduced it to '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub DeleteAllNamedRange() Dim lngNamesCount As Long Dim intPtr As Integer 'Get the nr of named ranges lngNamesCount = Application.Names.Count For intPtr = 1 To lngNamesCount Names(intPtr).Delete Next intPtr End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Then, on the first run, with 18 named ranges, when intPtr reached 10, it returned 'subscript out of range'. That left me with 9 named ranges. Running again from this point returned 'subscript out of range' when intPtr reached 6, leaving me with 4 named ranges. Again when intPtr reached 3 .... After several reps, all of the named ranges were gone, so I tried the 'real' test of calling this routine as the last step of the routine that gets the external data. On this run the newly created named range was deleted, but the macro still returned the 'subscript out of range' error. Ideas? "affordsol" wrote: Hello, You'll find below some code which should help you ... someway. Glad to help+ '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub ShowAllNamedRanges() Dim lngNamesCount As Long Dim intPtr As Integer Dim strNamedRanges As String 'Get the nr of named ranges lngNamesCount = Application.Names.Count 'Empty the strNamedRanges text strNamedRanges = "" For intPtr = 1 To lngNamesCount strNamedRanges = strNamedRanges & vbCrLf & intPtr & " = " & Names(intPtr).Name Next intPtr MsgBox strNamedRanges End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub DeleteOneNamedRange() Dim lngNamesCount As Long Dim intPtr As Integer Dim strNamedRanges As String 'Get the nr of named ranges lngNamesCount = Application.Names.Count 'Empty the strNamedRanges text strNamedRanges = "" 'Put list of Named Ranges in strNamedRanges For intPtr = 1 To lngNamesCount strNamedRanges = strNamedRanges & vbCrLf & intPtr & " = " & Names(intPtr).Name Next intPtr Dim strPrompt, strTitle, strDefault, strConfirm As String Dim intIndexOfRangeToBeDeleted As Integer strTitle = "Delete one Named Range" strDefault = "" strPrompt = strNamedRanges & vbCrLf & "Input the index of the Named Range to be deleted ..." intIndexOfRangeToBeDeleted = Val(InputBox(strPrompt, strTitle, strDefault)) If intIndexOfRangeToBeDeleted 0 Then strTitle = strTitle & " CONFIRM..." strPrompt = "DELETE " & Names(intIndexOfRangeToBeDeleted) & vbCrLf & "<Yes or <No..." strConfirm = InputBox(strPrompt, strTitle, strDefault) If Left(strConfirm, 1) = "Y" Then Names(intIndexOfRangeToBeDeleted).Delete End If End If End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES -- Herve Hanuise http://www.affordsol.be "EdStevens" wrote: Excel 2003 on XP Pro Every day I receive a text file with a single record (space delimited). I have written a macro to load that record into the next row of the worksheet, using Get External Data. All that is working fine, but in doing initial testing and debugging of the macro, I noticed that every time I bring in a new record, it creates a new external data range. I really don't need these defined data ranges, I just need the values loaded in. Really just a housekeeping issue ... several months from now, when I have 100+ rows of data, do I really want to have 100+ different external data ranges defined? Or am I obsessing about a non-issue? Is there some way to clean-up/delete the range definitions without deleting the data (cell values) itself? |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
There's a caveat with the deletion of all the names from 1 to lngNamesCount. Think of a list of 10 elements, each numbered from 1 to 10. If you delete item #1, the item#2 will now be #1 ... and so on. So, according to me, the loop you want is: For intPtr = lngNamesCount To 1 Step -1 Names(intPtr).Delete Next intPtr always glad to help... -- Herve Hanuise http://www.affordsol.be "EdStevens" wrote: Well, that was essentially what I needed .... ;-) After playing around with the code you provided and seeing how it works, for my purposes I reduced it to '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub DeleteAllNamedRange() Dim lngNamesCount As Long Dim intPtr As Integer 'Get the nr of named ranges lngNamesCount = Application.Names.Count For intPtr = 1 To lngNamesCount Names(intPtr).Delete Next intPtr End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Then, on the first run, with 18 named ranges, when intPtr reached 10, it returned 'subscript out of range'. That left me with 9 named ranges. Running again from this point returned 'subscript out of range' when intPtr reached 6, leaving me with 4 named ranges. Again when intPtr reached 3 .... After several reps, all of the named ranges were gone, so I tried the 'real' test of calling this routine as the last step of the routine that gets the external data. On this run the newly created named range was deleted, but the macro still returned the 'subscript out of range' error. Ideas? "affordsol" wrote: Hello, You'll find below some code which should help you ... someway. Glad to help+ '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub ShowAllNamedRanges() Dim lngNamesCount As Long Dim intPtr As Integer Dim strNamedRanges As String 'Get the nr of named ranges lngNamesCount = Application.Names.Count 'Empty the strNamedRanges text strNamedRanges = "" For intPtr = 1 To lngNamesCount strNamedRanges = strNamedRanges & vbCrLf & intPtr & " = " & Names(intPtr).Name Next intPtr MsgBox strNamedRanges End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub DeleteOneNamedRange() Dim lngNamesCount As Long Dim intPtr As Integer Dim strNamedRanges As String 'Get the nr of named ranges lngNamesCount = Application.Names.Count 'Empty the strNamedRanges text strNamedRanges = "" 'Put list of Named Ranges in strNamedRanges For intPtr = 1 To lngNamesCount strNamedRanges = strNamedRanges & vbCrLf & intPtr & " = " & Names(intPtr).Name Next intPtr Dim strPrompt, strTitle, strDefault, strConfirm As String Dim intIndexOfRangeToBeDeleted As Integer strTitle = "Delete one Named Range" strDefault = "" strPrompt = strNamedRanges & vbCrLf & "Input the index of the Named Range to be deleted ..." intIndexOfRangeToBeDeleted = Val(InputBox(strPrompt, strTitle, strDefault)) If intIndexOfRangeToBeDeleted 0 Then strTitle = strTitle & " CONFIRM..." strPrompt = "DELETE " & Names(intIndexOfRangeToBeDeleted) & vbCrLf & "<Yes or <No..." strConfirm = InputBox(strPrompt, strTitle, strDefault) If Left(strConfirm, 1) = "Y" Then Names(intIndexOfRangeToBeDeleted).Delete End If End If End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES -- Herve Hanuise http://www.affordsol.be "EdStevens" wrote: Excel 2003 on XP Pro Every day I receive a text file with a single record (space delimited). I have written a macro to load that record into the next row of the worksheet, using Get External Data. All that is working fine, but in doing initial testing and debugging of the macro, I noticed that every time I bring in a new record, it creates a new external data range. I really don't need these defined data ranges, I just need the values loaded in. Really just a housekeeping issue ... several months from now, when I have 100+ rows of data, do I really want to have 100+ different external data ranges defined? Or am I obsessing about a non-issue? Is there some way to clean-up/delete the range definitions without deleting the data (cell values) itself? |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry Ed,
I didn't realize you wanted to delete ALL named ranges at once : here's the solution Sub DeleteAllNamedRanges() Dim objName As Name For Each objName In ActiveWorkbook.Names objName.Delete Next objName End Sub regards+ -- Herve Hanuise http://www.affordsol.be "EdStevens" wrote: Well, that was essentially what I needed .... ;-) After playing around with the code you provided and seeing how it works, for my purposes I reduced it to '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub DeleteAllNamedRange() Dim lngNamesCount As Long Dim intPtr As Integer 'Get the nr of named ranges lngNamesCount = Application.Names.Count For intPtr = 1 To lngNamesCount Names(intPtr).Delete Next intPtr End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Then, on the first run, with 18 named ranges, when intPtr reached 10, it returned 'subscript out of range'. That left me with 9 named ranges. Running again from this point returned 'subscript out of range' when intPtr reached 6, leaving me with 4 named ranges. Again when intPtr reached 3 .... After several reps, all of the named ranges were gone, so I tried the 'real' test of calling this routine as the last step of the routine that gets the external data. On this run the newly created named range was deleted, but the macro still returned the 'subscript out of range' error. Ideas? "affordsol" wrote: Hello, You'll find below some code which should help you ... someway. Glad to help+ '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub ShowAllNamedRanges() Dim lngNamesCount As Long Dim intPtr As Integer Dim strNamedRanges As String 'Get the nr of named ranges lngNamesCount = Application.Names.Count 'Empty the strNamedRanges text strNamedRanges = "" For intPtr = 1 To lngNamesCount strNamedRanges = strNamedRanges & vbCrLf & intPtr & " = " & Names(intPtr).Name Next intPtr MsgBox strNamedRanges End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES Sub DeleteOneNamedRange() Dim lngNamesCount As Long Dim intPtr As Integer Dim strNamedRanges As String 'Get the nr of named ranges lngNamesCount = Application.Names.Count 'Empty the strNamedRanges text strNamedRanges = "" 'Put list of Named Ranges in strNamedRanges For intPtr = 1 To lngNamesCount strNamedRanges = strNamedRanges & vbCrLf & intPtr & " = " & Names(intPtr).Name Next intPtr Dim strPrompt, strTitle, strDefault, strConfirm As String Dim intIndexOfRangeToBeDeleted As Integer strTitle = "Delete one Named Range" strDefault = "" strPrompt = strNamedRanges & vbCrLf & "Input the index of the Named Range to be deleted ..." intIndexOfRangeToBeDeleted = Val(InputBox(strPrompt, strTitle, strDefault)) If intIndexOfRangeToBeDeleted 0 Then strTitle = strTitle & " CONFIRM..." strPrompt = "DELETE " & Names(intIndexOfRangeToBeDeleted) & vbCrLf & "<Yes or <No..." strConfirm = InputBox(strPrompt, strTitle, strDefault) If Left(strConfirm, 1) = "Y" Then Names(intIndexOfRangeToBeDeleted).Delete End If End If End Sub '===ROUTINES===ROUTINES===ROUTINES===ROUTINES===RO UTINES -- Herve Hanuise http://www.affordsol.be "EdStevens" wrote: Excel 2003 on XP Pro Every day I receive a text file with a single record (space delimited). I have written a macro to load that record into the next row of the worksheet, using Get External Data. All that is working fine, but in doing initial testing and debugging of the macro, I noticed that every time I bring in a new record, it creates a new external data range. I really don't need these defined data ranges, I just need the values loaded in. Really just a housekeeping issue ... several months from now, when I have 100+ rows of data, do I really want to have 100+ different external data ranges defined? Or am I obsessing about a non-issue? Is there some way to clean-up/delete the range definitions without deleting the data (cell values) itself? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Importing External Data Question | Excel Worksheet Functions | |||
External Data Queries - Data Range Properties v Spreadsheet Format | Excel Discussion (Misc queries) | |||
insert entire row for new data, external data range doesnt work | Excel Programming | |||
How can I check if data in an external data range is changed afte. | Excel Worksheet Functions | |||
import external data via macro/vba question | Excel Programming |