Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Changing Range of Defined Name in Excel


Reply
 
Thread Tools Display Modes
  #1  
Old 03-20-2003, 06:33 AM
Skibum346 Skibum346 is offline
Newcomer
 
Join Date: Nov 2002
Posts: 3
Question Changing Range of Defined Name in Excel


Dear All,

I want to set up a script to extend the range of an already defined named array in Excel. The array is a lookup list for a drop down field that I want the user to be able to add to, without leaving unsightly blank lines in the range.

I have created a formula that outputs the range formula of the increased list. How do I adjust the name definition using VB?

And I should probably mention I'm a complete beginner so example code would be a distinct advantage!

Many Thanks in advance!

Skibum
Reply With Quote
  #2  
Old 03-20-2003, 07:29 AM
mconnolly mconnolly is offline
Newcomer
 
Join Date: Feb 2003
Posts: 14
Default

Redimension the array using the preserve keyword to avoid destroying its current contents, and then add the new member to the end.

Metacode=================================

redim preserve arrayName(ubound(arrayName)+1)
arrayName(ubound(arrayName)) = Whatever

========================================
__________________
I have learned from my mistakes and feel confident that I can repeat them in future.
Reply With Quote
  #3  
Old 03-21-2003, 12:01 PM
Judo Tom Judo Tom is offline
Freshman
 
Join Date: Oct 2002
Posts: 39
Default

how do you retrieve a named range that is on an excel worksheet?
Reply With Quote
  #4  
Old 03-24-2003, 03:14 AM
mconnolly mconnolly is offline
Newcomer
 
Join Date: Feb 2003
Posts: 14
Default

Quote:
Originally Posted by Judo Tom
how do you retrieve a named range that is on an excel worksheet?



I'm not quite sure what you're asking for, but I suspect you might be able to use the CurrentRegion property.

CurrentRegion will return a range of contiguous used cells from a single cell reference.

To test this, try opening a new sheet, typing some text in cell a1, and then filling down to cell a7. Then open the visual basic editor, double-click on the relevant sheet to open its code window, and type:

Code:
Sub GetRange() Dim myRange As Range Set myRange = Me.Cells(4, 1).CurrentRegion Debug.Print myRange.Address Set myRange = Nothing End Sub

It should return $A$1:$A$7 - the address of the region containing cell A4.
__________________
I have learned from my mistakes and feel confident that I can repeat them in future.
Reply With Quote
  #5  
Old 03-24-2003, 05:52 AM
Judo Tom Judo Tom is offline
Freshman
 
Join Date: Oct 2002
Posts: 39
Default

Thanks for the response.. i actually got it to work using the following:
Dim objExcel As Excel.Application
Dim ratiocy As Excel.Worksheet
Dim copiedchart As Object
Dim xlwrksheet As Excel.Worksheet
Dim comprange As Excel.Range
Dim myNamed As Excel.Range
objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open("c:\test.xls")
objExcel.DisplayAlerts = False
objExcel.Visible = False
ratiocy = objexcel.Worksheets(1)
myNamed = ratiocy.Range(layoutvalue(x, 4))
myNamed.Copy()
With objExcel ' Use With...End With so you don't have to type objExcel over and over again

.ActiveWorkbook.Close()
.Quit()
End With
objExcel = Nothing
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Selection range problem biafra Excel 1 03-19-2003 06:03 AM
Write to another range from an excel function mickboland Word, PowerPoint, Outlook, and Other Office Products 11 11-17-2002 08:41 PM
Excel VBA Error: User Defined Type Not Defined EACutter Word, PowerPoint, Outlook, and Other Office Products 1 11-15-2002 12:12 AM
best way to access other MS applications internationally Word, PowerPoint, Outlook, and Other Office Products 1 10-21-2002 07:51 PM
Naming an Excel range TrentG Word, PowerPoint, Outlook, and Other Office Products 6 10-04-2002 07:45 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->