473,765 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel range to Array to Listbox

Sub ExcelToListBox( )
Dim xRange As Object
Dim ary
Dim xValue As String

xRange = oXL.Range("A1:A 9") 'has letters A-H
ary = xRange.value
xValue = ary(3, 1) 'xValue = C
Me.ListBoxPerso n.Items.AddRang e(ary)

This AddRange causes error message:
'An unhandled exception of type
'System.Reflect ion.AmbiguousMa tchException' occurred in
microsoft.visua lbasic.dll
'Additional information: No accessible overloaded
'ObjectCollecti on.AddRange' can be called without a narrowing
conversion.

End Sub


Questions:
Is there a difference between these two:
Dim ary
Dim ary as System.Array
What is the syntax for the AddRange? I've tried various combinations.

Thanks,
George
Nov 20 '05 #1
3 8899
No replies yet, so I'll explain this newbie question another way:

How do you transfer data from an "Excel range" array to a listbox?

I've used this code with "normal" arrays:
dim Ary1() as String
[slow transfer of Excel data in "For-Next" code into Ary1]
xValue = Ary1(2) 'xValue = C
me.listbox1.Add Range(Ary1) 'this works

To transfer data (faster) from an Excel range:
dim Ary2 'not normal way to declare an array
dim xRange as Object
xRange = oXL.Range("A1:A 9") 'has letters A-H
Ary2 = xRange.value 'this works
xValue = Ary2(3, 1) 'xValue = C
'not normal way to access array values
me.listbox1.Add Range(Ary2) 'error message (see my first post)

It's obvious that Ary2 is a Different kind of object than Ary1.
Have you seen any explanations for this?

Can this kind of array (from Excel range) be used in Listbox.AddRang e?
If not, any suggestions to do it other ways?

Thanks for your help on either question,
George
te*****@hotmail .com (George) wrote in message news:<c1******* *************** ****@posting.go ogle.com>...
Sub ExcelToListBox( )
Dim xRange As Object
Dim ary
Dim xValue As String

xRange = oXL.Range("A1:A 9") 'has letters A-H
ary = xRange.value
xValue = ary(3, 1) 'xValue = C
Me.ListBoxPerso n.Items.AddRang e(ary)

This AddRange causes error message:
'An unhandled exception of type
'System.Reflect ion.AmbiguousMa tchException' occurred in
microsoft.visua lbasic.dll
'Additional information: No accessible overloaded
'ObjectCollecti on.AddRange' can be called without a narrowing
conversion.

End Sub


Questions:
Is there a difference between these two:
Dim ary
Dim ary as System.Array
What is the syntax for the AddRange? I've tried various combinations.

Thanks,
George

Nov 20 '05 #2
This seems to be the problem:
When Ary2 = xRange.value, the rank (number of dimensions) of Ary2 is
set to 2.
But "listbox1.AddRa nge" evidently allows only single-dimensional
arrays.?

If that is true, is there a way to copy a specific dimension of a
multi-dimensional array to a single-dimensional array?
I tried Array.Copy without success.

I'm not getting very much help here; is this a dumb question or what?
Would ArrayList or something else work better?

Thanks,
George
te*****@hotmail .com (George) wrote in message news:<c1******* *************** ****@posting.go ogle.com>...
No replies yet, so I'll explain this newbie question another way:

How do you transfer data from an "Excel range" array to a listbox?

I've used this code with "normal" arrays:
dim Ary1() as String
[slow transfer of Excel data in "For-Next" code into Ary1]
xValue = Ary1(2) 'xValue = C
me.listbox1.Add Range(Ary1) 'this works

To transfer data (faster) from an Excel range:
dim Ary2 'not normal way to declare an array
dim xRange as Object
xRange = oXL.Range("A1:A 9") 'has letters A-H
Ary2 = xRange.value 'this works
xValue = Ary2(3, 1) 'xValue = C
'not normal way to access array values
me.listbox1.Add Range(Ary2) 'error message (see my first post)

It's obvious that Ary2 is a Different kind of object than Ary1.
Have you seen any explanations for this?

Can this kind of array (from Excel range) be used in Listbox.AddRang e?
If not, any suggestions to do it other ways?

Thanks for your help on either question,
George
te*****@hotmail .com (George) wrote in message news:<c1******* *************** ****@posting.go ogle.com>...
Sub ExcelToListBox( )
Dim xRange As Object
Dim ary
Dim xValue As String

xRange = oXL.Range("A1:A 9") 'has letters A-H
ary = xRange.value
xValue = ary(3, 1) 'xValue = C
Me.ListBoxPerso n.Items.AddRang e(ary)

This AddRange causes error message:
'An unhandled exception of type
'System.Reflect ion.AmbiguousMa tchException' occurred in
microsoft.visua lbasic.dll
'Additional information: No accessible overloaded
'ObjectCollecti on.AddRange' can be called without a narrowing
conversion.

End Sub
>


Questions:
Is there a difference between these two:
Dim ary
Dim ary as System.Array
What is the syntax for the AddRange? I've tried various combinations.

Thanks,
George

Nov 20 '05 #3
My "final answer", in moving data from Excel range to Listbox items:

Solution 1, needs one array, OK for small range.
1a. Excel to array

Dim Ary1() as string
'one-dimensional array acceptable to Listbox.Items.A ddRange
For...Next, transfer values from Excel to Ary1

1b. Array to Listbox
Listbox.Items.A ddRange(Ary1)
------------------------------------------

Solution 2, needs two arrays, better for large ranges.
2a. Excel to array

Dim Ary2 as System.Array
Dim xRange as Object
xRange = oXL.Range("A1:A 930")
Ary2 = xRange.value 'Ary2 now has rank of 2, base 1

2b. Transfer data from two-dimensional to one-dimensional array.
Could not find a command to do this.
Redim cannot change the array's rank.
The For...Next here goes much faster than the one in step 1a.

Dim Ary3(UBound(Ary 2, 1) - 1) as String
'Ary2 uses base 1, Ary3 uses base 0.
'Need to decrement by one for normal array with base zero
Dim n2 as Integer
Dim n3 as Integer
For n2 = 1 to UBound(Ary2,1)
'read items from Ary2 starting at 1
n3 = n2 -1
Ary3(n3) = Ary2(n2, 1)
'transfer to Ary3 starting at zero
Next n2

2c. Array to Listbox
Listbox.Items.A ddRange(Ary3)
---------------

I could not find these steps explained in Microsoft help or in other posts here.

George

te*****@hotmail .com (George) wrote in message news:<c1******* *************** ****@posting.go ogle.com>...
This seems to be the problem:
When Ary2 = xRange.value, the rank (number of dimensions) of Ary2 is
set to 2.
But "listbox1.AddRa nge" evidently allows only single-dimensional
arrays.?

If that is true, is there a way to copy a specific dimension of a
multi-dimensional array to a single-dimensional array?
I tried Array.Copy without success.

I'm not getting very much help here; is this a dumb question or what?
Would ArrayList or something else work better?

Thanks,
George
te*****@hotmail .com (George) wrote in message news:<c1******* *************** ****@posting.go ogle.com>...
No replies yet, so I'll explain this newbie question another way:

How do you transfer data from an "Excel range" array to a listbox?

I've used this code with "normal" arrays:
dim Ary1() as String
[slow transfer of Excel data in "For-Next" code into Ary1]
xValue = Ary1(2) 'xValue = C
me.listbox1.Add Range(Ary1) 'this works

To transfer data (faster) from an Excel range:
dim Ary2 'not normal way to declare an array
dim xRange as Object
xRange = oXL.Range("A1:A 9") 'has letters A-H
Ary2 = xRange.value 'this works
xValue = Ary2(3, 1) 'xValue = C
'not normal way to access array values
me.listbox1.Add Range(Ary2) 'error message (see my first post)

It's obvious that Ary2 is a Different kind of object than Ary1.
Have you seen any explanations for this?

Can this kind of array (from Excel range) be used in Listbox.AddRang e?
If not, any suggestions to do it other ways?

Thanks for your help on either question,
George
te*****@hotmail .com (George) wrote in message news:<c1******* *************** ****@posting.go ogle.com>...
Sub ExcelToListBox( )
Dim xRange As Object
Dim ary
Dim xValue As String

xRange = oXL.Range("A1:A 9") 'has letters A-H
ary = xRange.value
xValue = ary(3, 1) 'xValue = C
Me.ListBoxPerso n.Items.AddRang e(ary)

This AddRange causes error message:
'An unhandled exception of type
'System.Reflect ion.AmbiguousMa tchException' occurred in
microsoft.visua lbasic.dll
'Additional information: No accessible overloaded
'ObjectCollecti on.AddRange' can be called without a narrowing
conversion.

End Sub
>>

Questions:
Is there a difference between these two:
Dim ary
Dim ary as System.Array
What is the syntax for the AddRange? I've tried various combinations.

Thanks,
George

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3372
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to process this .txt file. Goal: I am working on a vba script to:
1
1248
by: Greg | last post by:
I tried following the code below from the microsoft article Q306022 to copy an array of data to excel in a single call. I only have a single dimension in my array. The problem I have is that even though the call: oSheet.Range("A2").Resize(100, 3).Value = DataArray works it only copies the first item from my DataArray. It copies this value to each item in the defined range in Excel. It's as if excel does not recognize that I'm...
5
4498
by: Lee | last post by:
Hi All, My problem is trying to figure out how to get the numbers from a range of cells in Excel into an array (double) in a VB.NET program, do something with the array, and then send it back to the spreadsheet. I AM able to open an exiting Excel spreadsheet and do this with a single cell but not an array. In addition, I can send an array from the VB.NET program to a range of cells in Excel but I can't for the life of me figure out how...
2
24460
by: George | last post by:
Is there a fast way to transfer an Excel range to an array? Example: Excel range is E2:E300 Dim person() as string Thanks, George
2
1799
by: Doug Glancy | last post by:
Dim temp(Me.TimeIncrementListBox.Items.Count) As String Dim i As Int32 .... For i = 0 To UBound(temp) - 1 temp(i) = CType(Me.TimeIncrementListBox.Items(i), String) Next xlSheet.Range("X10").Resize(1, Me.TimeIncrementListBox.Items.Count).Value = temp The above works but,
18
8290
by: Frank M. Walter | last post by:
Hello, I have made an small AddIn with udf for excel 2003. I use vs2003. The point of view is the function __T() I call it in excel sheet writing =__T() I am not able to set a value to a given cell. region.Value2="qwe"; //bumm! A exception will be trown. On all PCs with excel. HRESULT 0x800A03EC
2
1793
by: dan NY | last post by:
I'm a struggling new VB Applications user that has what may be a simple question, but I've been struggling with it. I'm using a response to a message box YesNo question to cause one of two previously created listboxes to populate. These listboxes are each linked to ranges of cells that appear or are blanked out by IF statements in excel formulas =IF(a1=1,"company name","") - the contents of cell A1 becomes 1 based on an affirmative response...
3
16011
by: toffee | last post by:
Hi all, I got a pre-formatted spreadsheet. would it be possible using js to copy the data from a table on the current webpage, open the spreadsheet and paste the content ? if so, anyone got any links or pointers? i've already tried google - but all i get is ActiveX methods which work in a very few cases.
2
2257
by: gellis72 | last post by:
I'm working on a program that imports a bunch of data from a folder full of Excel files and compiles it into an Access DB. The Excel files have a varying number of rows and columns that need to be imported, and the data needs to be processed/error checked before it's written to the DB. The way I've tackled this is to have a procedure that steps through a list of Excel files, invokes an instance of Excel, opens file "x", copies the relevant...
0
10161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9833
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.