Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning whole row from Excel

Status
Not open for further replies.

uprichard

Programmer
May 2, 2002
16
I have been able to return one cell at a time from excel using

a=ExcelSheet.ActiveSheet.Cells(Row_Number,2).Value

But can I return the whole row into an array?


Also does anyone know how to change the active sheet that the data will be pulled back from.

Thanks for any help
 
You may be able to use the File System Object Model (FSO Model) to loop through the fields in excel, and build your array. I'm kind of new to the whole FSO Model, but you can do stuff like

set fso = Server.CreateObject("Scripting.FileSystemObject")
set FileRead = fso_OpenTextFile(FileLocation,ForReading)

dim FileRead
dim Counter
Counter = 0

Do until FileRead.endofline = true


Then you could set i as a variable for the number of rows in the speadsheet, and build your loop to have one variable for each row. For the end of file, use AtEndOfStream. I don't know if this helped, or confused, but good luck.
 
Ok, first place to look for help is Excel:
Open Excel,
Hit ALT+F11, then F1 (opens VB and then VB help)
Search for "Range"

Your code will probably end up looking something like this:

Code:
'Optional loop to find the row you need
varRow = 1
Do While ExcelSheet.ActiveSheet.Cells(varRow, 1).Value > ""
    If ExcelSheet.ActiveSheet.Cells(varRow, 1).Value = <What You Want>
        Exit Do
    End If
    varRow = varRow + 1
Loop

A = Array(ExcelSheet.ActiveSheet.Range(varRow:varRow))
'According to what I read, this should grab the entire row

I didn't test this, but hopefully it will help you out... [peace]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top