How to read values of an excel worksheet cells into an array in visual basic
Posted on 2007-10-17
I am getting a set of words from the back end and I am writing them back into a specific worksheet of an excel file in the following fashion. I am also pasting the code for getting values from the data table:
objConn1.ConnectionString = "Provider=SQLOLEDB;database=" & LibName & ";SERVER=" & Srvr & ";User id=sa;password=dserv"
Set objcommand1.ActiveConnection = objConn1
sqlStatement1 = "SELECT DISTINCT USR.U_NAME FROM " & LibName & ".dbo.USR USR, " & LibName & ".dbo.ELEMENT ELE WHERE ELE.E_INA07 IS NULL AND USR.U_NAME=ELE.E_OWNER "
objcommand1.CommandText = sqlStatement1
Set recset = objcommand1.Execute
For example purpose, let us say I have a workbook with three worksheets (Sheet1, Sheet2 and Sheet3). And worksheet (Sheet3) has the following two columns with corresponding values
Header 1(In Column A) Header 2 (In Column B)
I am trying to read values off of an excel file and I want to load the values of each cell into an array.
In the above example, I want to read all the values under Header 1 into vArray1 and values under header 2 into vArray2. But at the same time both the values should be properly related - meaning - if I want to print the value of vArray1 and vArray2 at index 1, then I should get Value1 and Value1A
Thanks for all the help offered