473,770 Members | 3,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel range to array

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
Nov 20 '05 #1
2 24460
Hi
A range in excel is an array
ie

Dim ary As Range
Set ary = Range("E2:E300" )

Debug.Print ary(0, 1)
Debug.Print ary(1, 1)
Debug.Print ary(2, 1)
Debug.Print ary(3, 1)

gets e1 to e4 values
and so on

Regards
James

"George" <te*****@hotmai l.com> wrote in message
news:c1******** *************** ***@posting.goo gle.com...
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

Nov 20 '05 #2
James,
Thanks for your reply.

I should have stated the purpose of the array - to populate a control.

Current code:
1. Define the array
dim personArray() as string

2. For-next sub to move values from Excel to the array:
personArray(i) = oXL.Cells(ThisR ow, 1).value
(this sub does the dim preserve to update the array's index.)

3. Move values from array to control.
ComboBoxPerson. Items.AddRange( personArray)
I tried your suggestion (modifying it a bit):

1. Define the range
Dim xrange As Excel.Range
xrange = oXL.Range("E2:E 300")

2. Move values from range to control.
ComboBoxPerson. Items.AddRange( xrange)

I get this vb.net Build error on last line, with xrange highlighted:
Value of type 'Excel.Range' cannot be converted to '1-dimensional array of string'.

Same error and highlight occurs with this:
Dim xrange As Excel.Range
xrange = oXL.Range("E2:E 300")
personArray = xrange

A valid way to say this last line is what I'm looking for.

Thanks,
George

ps.
I have vb.net 2003 and Excel 2000.
The modules have:
Imports System
Imports System.io
Imports Microsoft.Visua lBasic

ps2.
On this reply, I changed the Subject line, adding "- populate control";
not sure how Google handles this.


"James Lang" <j.****@blueyon der.co.uk> wrote in message news:<e5******* *******@tk2msft ngp13.phx.gbl>. .. Hi
A range in excel is an array
ie

Dim ary As Range
Set ary = Range("E2:E300" )

Debug.Print ary(0, 1)
Debug.Print ary(1, 1)
Debug.Print ary(2, 1)
Debug.Print ary(3, 1)

gets e1 to e4 values
and so on

Regards
James

"George" <te*****@hotmai l.com> wrote in message
news:c1******** *************** ***@posting.goo gle.com...
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

Nov 20 '05 #3

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
4500
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...
3
8900
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C Me.ListBoxPerson.Items.AddRange(ary)
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
3
13606
by: implicate_order | last post by:
Greetings, I'm new to python and am in the process of writing a script to parse some CSV data, spread it across multiple Excel worksheets and then generate charts. I searched the internet to find some place where I could look up a HOWTO doc/recipe to do that using either pyExcelerator or win32com.client. Could someone point me in the right direction? I'm at the stage where the spreadsheet and associated data worksheets
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.
0
3066
by: blainegray | last post by:
Greetings This is one of those Access is not closing Excel problems. The first time through the code works fine. The second time there is a problem. After lots of combinations, I finally determined that if I take out the line that copies the temp array to cells in a worksheet, Access will close the Excel file. If the line is there, Excel remains open and blocks more runs of the same procedure. If I close Access, Excel gets closed. Looks like...
2
2258
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
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
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
5312
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
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
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
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
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.