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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through and get each cell Data

Status
Not open for further replies.

hsingh1981

Programmer
Apr 8, 2008
56
GB
Hi all,

I have a problem, I can open an excel sheet and retrieve a paticular cell data and store it to my table. How do i tell it to go through each cell and move down and store it excel table?

eg.
a9
a10
a11
and retrieve the data in each cell and save it to table?

This is what i got so far with one cell

Code:
DoCmd.SetWarnings False
DoCmd.Hourglass True
Dim cFso

Set cFso = CreateObject("Scripting.FileSystemObject")
Dim MyProperPath As String
Dim myRec As DAO.Recordset
Dim xlApp, xlApp2 As Excel.Application
Dim xlWrksht, xlWrkshtBBE As Excel.Worksheet

'Name of Table
Set myRec = CurrentDb.OpenRecordset("T_LOS")
'Excel sheet creat and finding path
Set xlApp = CreateObject("Excel.Application")



'Make sure the path is in the right format
MyProperPath = txtExcelFileLocation


Set xlWrksht = xlApp.Workbooks.Open(MyProperPath)




'MsgBox MyFileName
myRec.AddNew

myRec.Fields("HRGs") = xlWrksht.Worksheets("Length of Stay").Cells(9, "A")


myRec.Update

xlApp.Workbooks.Close
DoCmd.SetWarnings True

'Me.Combo14.Requery

DoCmd.Hourglass False


Many thanks
 

Using a loop
Code:
'MsgBox MyFileName
for counter = 9 to 11
myRec.AddNew

myRec.Fields("HRGs") = xlWrksht.Worksheets("Length of Stay").Cells(counter, "A")


myRec.Update
next counter

there is also a fact to determine last cell used in a column if the range keeps changing.


ck1999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top