Hi guys,
I have been trying to understand which method to use for looping through excel cells and storing these into access tables. However, I am having difficulty with so little knowledge in vba.
I have lets say two tables (rows for each table are not fixed) in a worksheet and I want to loop through these rows and store each tables (PROJECT PLAN 1 and PROJECT PLAN 2) in a separate table in access.
PROBLEM: I don't know how to loop through the PROJECT PLAN 1 and PROJECT PLAN 2 in excel and store these in table1 and table2 in access
I have these in excel
B3 I have "PROJECT PLAN 1"
B4 COMPANY | C4 DESCRIPTION | D4 TIME
B5 Google | C5 aaa | D5 10
B6 Microsoft | C6 bbb | D6 11
B7 IBM | C7 ccc | D7 12
next row 8 is blank row and columns
B9 I have "PROJECT PLAN 2"
B10 COMPANY | C10 DESCRIPTION | D10 TIME
B11 Google | C11 aaa | D11 10
B12 Microsoft | C12 bbb | D12 11
B13 B14(merge cell) IBM | C13 ccc | D13 12
B13 B14(merge cell) IBM | C14 ccc | D14 12
This is the code I have so far:
Thanks in advance.
I have been trying to understand which method to use for looping through excel cells and storing these into access tables. However, I am having difficulty with so little knowledge in vba.
I have lets say two tables (rows for each table are not fixed) in a worksheet and I want to loop through these rows and store each tables (PROJECT PLAN 1 and PROJECT PLAN 2) in a separate table in access.
PROBLEM: I don't know how to loop through the PROJECT PLAN 1 and PROJECT PLAN 2 in excel and store these in table1 and table2 in access
I have these in excel
B3 I have "PROJECT PLAN 1"
B4 COMPANY | C4 DESCRIPTION | D4 TIME
B5 Google | C5 aaa | D5 10
B6 Microsoft | C6 bbb | D6 11
B7 IBM | C7 ccc | D7 12
next row 8 is blank row and columns
B9 I have "PROJECT PLAN 2"
B10 COMPANY | C10 DESCRIPTION | D10 TIME
B11 Google | C11 aaa | D11 10
B12 Microsoft | C12 bbb | D12 11
B13 B14(merge cell) IBM | C13 ccc | D13 12
B13 B14(merge cell) IBM | C14 ccc | D14 12
This is the code I have so far:
Code:
Dim objXL As Object
Dim xlSht As Object
Dim xlWB As Object
Set objXL = CreateObject("Excel.Application")
Set xlWB = objXL.Workbooks.Open(txtExcelFile.Value) 'assuming txtExcelFile.Value is aa.xlsx
Set xlSht = xlWB.Worksheets(cboExcelFile.Value) 'assuming cboExcelFile.Value is the worksheet name Sheet1
For Each cell In xlSht.UsedRange.Cells
If cell.Value = "PROJECT PLAN 1" Then
'next row as column headers will be imported to access table1
'follwing row as values
'stops if an emplty cell is found (for example b8)
Elseif cell.Value = "PROJECT PLAN 2" Then
'next row as column headers will be imported to access table2
'follwing row as values
End If
Next
Thanks in advance.
Last edited: