472,373 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

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 24343
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*****@hotmail.com> wrote in message
news:c1**************************@posting.google.c om...
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(ThisRow, 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:E300")

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:E300")
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.VisualBasic

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


"James Lang" <j.****@blueyonder.co.uk> wrote in message news:<e5**************@tk2msftngp13.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*****@hotmail.com> wrote in message
news:c1**************************@posting.google.c om...
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
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...
1
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...
5
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...
3
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...
18
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...
3
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...
3
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...
0
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...
2
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.