473,385 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

display range

23
i can get a single value from a worksheet using vb.net and excel.

q)How do i get a range of values eg A2 to A5 and print them out eg with a msgbox. I know i can use the cells command but i want a range command where specify excel cell range.

'MyString = XL.Cells(4, 1).Value
MyString = XL.Range("A2", "A5").Value 'error
MsgBox(MyString)
Mar 6 '08 #1
11 1309
QVeen72
1,445 Expert 1GB
Hi,

I Guess, Return Range should be assigned to an Array:

Try This :

Dim MyArr() As String
MyArr = XL.Range("A2:A5").Value

And Loop through MyArr, to get all the Values..

Regards
Veena
Mar 6 '08 #2
kadghar
1,295 Expert 1GB
Hi,

I Guess, Return Range should be assigned to an Array:

Try This :

Dim MyArr() As String
MyArr = XL.Range("A2:A5").Value

And Loop through MyArr, to get all the Values..

Regards
Veena
It wont work all the times for Strings array, try using a variant. The nice thing about asigning a Range to a Variant, is that the variant wont change into a Variant/Range, but into a Variant's array.
so

dim MyArr
MyArr = Range("A2:A5")

will make MyArr a 2 dimensioned array (1 to 4, 1 to 1) of variants, which index start in 1.

HTH
Mar 6 '08 #3
Killer42
8,435 Expert 8TB
dim MyArr
MyArr = Range("A2:A5")

will make MyArr a 2 dimensioned array (1 to 4, 1 to 1) of variants, which index start in 1.
That's weird. It seems pretty silly of it to create a two-dimensional array, don't you think? Then again, computers do work in mysterious ways.
Mar 7 '08 #4
kadghar
1,295 Expert 1GB
That's weird. It seems pretty silly of it to create a two-dimensional array, don't you think? Then again, computers do work in mysterious ways.
No, its quite useful when working with Excel's VBA, because you can use the same FOR for a range an its array. Also you can asign an 2 dimensioned array to a range, so it'll be writen in the worksheet. e.g.

range("A3,A5") = Arr

=) Where Arr is a 2 dimension array (1 to 3, 1 to 1)
Mar 7 '08 #5
jagguy
23
I asked this before but i still dont know

can i set a range of values from excel to a datagrid?
Mar 7 '08 #6
kadghar
1,295 Expert 1GB
I asked this before but i still dont know

can i set a range of values from excel to a datagrid?
can you asign an Array to a datagrid?
Mar 7 '08 #7
jagguy
23
i can assign a 1D array to a datagrid yes.
i cant assign a 2d array so i need to convert the 2d array to 1D array but i cant get rows and cols in a datagrid with rows and cols (just 1 col).

This is very complicated!
Mar 7 '08 #8
kadghar
1,295 Expert 1GB
i can assign a 1D array to a datagrid yes.
i cant assign a 2d array so i need to convert the 2d array to 1D array but i cant get rows and cols in a datagrid with rows and cols (just 1 col).

This is very complicated!
Expand|Select|Wrap|Line Numbers
  1. dim a 
  2. dim b()
  3. dim i as long
  4. a = range("a2:a5")
  5. redim b(1 to ubound(a))
  6. for i = 1 to ubound(a)
  7.     b(i) = a(i,1)
  8. next
And now b is your 1D array.

^.^
Mar 8 '08 #9
jagguy
23
i have a range "A2:B5" but i can convert to array.

the problme is assigning to a datagrid

datagrid1.datasource= myarray ' myarray is single array from 2D array

'the datagrid is just 1 col and i want rows and cols like the 2D array origanlly is.

it is messy
Mar 8 '08 #10
kadghar
1,295 Expert 1GB
i have a range "A2:B5" but i can convert to array.

the problme is assigning to a datagrid

datagrid1.datasource= myarray ' myarray is single array from 2D array

'the datagrid is just 1 col and i want rows and cols like the 2D array origanlly is.

it is messy
in my last post, 'a' is a 2D array, and then 'b' is the 1D array that you may use.
Mar 8 '08 #11
jagguy
23
i have used a datatable which is more effective. the trick is to fill data from excel2d array and copy to datatable.
Mar 8 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Follower | last post by:
Hi, I am working on a function to return extracts from a text document with a specific phrase highlighted (i.e. display the context of the matched phrase). The requirements are: * Match...
13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
0
by: denis | last post by:
Please help Here is my code. I was able to modified to go to main menu. But If user enter a value outside the range it should not go to the main menu. It should display only: cout<<"Please enter...
2
by: heri | last post by:
Can you please assist me on how to get the 2nd record in case there are 3 or more records of an employee, the query below gets the MAX and MIN BasicSalary. However, my MIN Basic Salary is wrong...
1
by: John Phelan-Cummings | last post by:
When I add the name of a new individual in a, bound form, it will not display that person’s name in a label control of a second unbound form. I have a scheduling program that I am working on. ...
0
by: crist135 | last post by:
Hi guys, I have successfully done the retrieving of PDF file from Sql Server BLOB. Though, some of the pdf files are displaying it nicely but in some, postscript is being displayed. I am using...
0
by: adubra | last post by:
Hi there, I am using a device context (DC) and a buffer to successfully draw to screen. However, when I update the DC at very high frame rate and drag the frame containing the image very quickly...
12
by: aravicha | last post by:
Hi , i want a sample perl code to display all the dates between a date range. say, the start_date=18/03/2007 and end_date=18/04/2007. here i want to print all the dates beween 18/03/2007 &...
1
by: iftekar14 | last post by:
i have to create this at VB express 2008 When the user clicks the Process Files button, do the following: Read and process the contents of each of the 6 files. Each file contains data in a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.