473,387 Members | 1,453 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,387 software developers and data experts.

Importing from Excel with a chaning range

Hi Everyone

Is it possible to import an Excel spreadsheet by range when the range is different for each sheet. There is only one sheet in the workbook. It comprises of a different number of jobs in the first column, it has weeks 1 to 52 across in thje sixth row. Also is it possible to use a fixed cell in the table to name the table it will export into. I can import the whole table easily enough but am struggling to accomodate moving ranges.

Thanks in advance

ChrisD
Nov 21 '06 #1
8 3989
NeoPa
32,556 Expert Mod 16PB
Try linking to the spreadsheet.
That way you can read what you need and process the file accordingly.
Nov 21 '06 #2
MMcCarthy
14,534 Expert Mod 8TB
Hi Everyone

Is it possible to import an Excel spreadsheet by range when the range is different for each sheet. There is only one sheet in the workbook. It comprises of a different number of jobs in the first column, it has weeks 1 to 52 across in thje sixth row. Also is it possible to use a fixed cell in the table to name the table it will export into. I can import the whole table easily enough but am struggling to accomodate moving ranges.

Thanks in advance

ChrisD
Hi ChrisD

What you are looking at is opening the worksheet in access choosing the range and inserting into an existing table or creating a new table in Access.

Just as an example the following would delete a row in a worksheet from access.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim sNow As String, sFile As String, sSheet As String 
  3. Dim xApp As Object, xWk As Object, xWs As Object 
  4.     sNow = Format(Date, " dd-mm-yyyy") & " " & Format(Time, "hhmm") 
  5.     sFile = "C:\My Documents\DSCP ANPR" & sNow & ".xls" 
  6.     sSheet = "VRM for Export" 
  7.     DoCmd.TransferSpreadsheet acExport, 8, sSheet, sFile, True 
  8.     Set xApp = CreateObject("Excel.Application") 
  9.     Set xWk = xApp.Workbooks.Open (sFile) 
  10.     Set xWs = xWk.Worksheets(Left(sSheet, 31)) 
  11.     xWs.Range("A1").EntireRow.Delete 
  12.     Set xWs = Nothing 
  13.     xWk.Close True 
  14.     Set xWk = Nothing 
  15.     xApp.Quit 
  16.     Set xApp = Nothing 
  17.  
Now I know you want to do something different, but you have to look at questions like do you have to search for the start and end of the range or is it a predetermined list.

Do you want to Insert each row in the range in excel as a record in a new or predefined table in access.

Think about what's involved and the amount of code. Then let me know what you want to do.
Nov 21 '06 #3
Hi
Thanks for the reply. I would have attached a couple of the spreadsheets in question to help clarify what I am trying to do (except I cant see how to do it). I know one end of the range will always be A7 and the other end will always be BB7, its the number of rows which changes. I have some code which allows me to import to a table using the excel file name to create a new table its just that it imports everything and I am lost in trying to work out the ranges.
Any assistance will be much appreciated.
ChrisD
Nov 22 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
Hi
Thanks for the reply. I would have attached a couple of the spreadsheets in question to help clarify what I am trying to do (except I cant see how to do it). I know one end of the range will always be A7 and the other end will always be BB7, its the number of rows which changes. I have some code which allows me to import to a table using the excel file name to create a new table its just that it imports everything and I am lost in trying to work out the ranges.
Any assistance will be much appreciated.

ChrisD
If that's the only problem you can set the range in the DoCmd.TransferSpreadsheet to "A7:BB10000". I'm just using 10,000 as an example. Pick a number you are confident the row count won't go past. Then just run a query to delete all null records from the table.

Syntax:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "TableName", "pathtofile", True, "A7:BB10000"
Nov 22 '06 #5
If that's the only problem you can set the range in the DoCmd.TransferSpreadsheet to "A7:BB10000". I'm just using 10,000 as an example. Pick a number you are confident the row count won't go past. Then just run a query to delete all null records from the table.

Syntax:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "TableName", "pathtofile", True, "A7:BB10000"
Hi
Thanks for this. I tried it and get an error message which reads
error 3709 the search key was not found in any record.
I have checked the spreadsheet to ensure that all the header fields have an entry and the format is set to general for all of them.
I have pasted my code below just incase I've done something stupid and now can't see the wood for the trees.

Private Sub bImport_Click()
On Error GoTo Err_bImport_Click

Me.tbHidden.SetFocus

If IsNull(tbFile) Or tbFile = "" Then
MsgBox "Please browse and select a valid file to import.", vbCritical, "Invalid File"
Else
If Dir("C:\Wren_Jobs\") <> "" Then
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, tbFileName, tbFile, -1, "A6:BB40"
MsgBox "Imported your file into the table."
Else
MsgBox "Your computer does not have a valid file so the import will not work.", vbInformation
End If
End If

Exit_bImport_Click:
Exit Sub

Err_bImport_Click:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_bImport_Click

End Sub

Thanks once again
Nov 23 '06 #6
MMcCarthy
14,534 Expert Mod 8TB
Are tbFileName and tbFile Global variables and how and where is their value being set?

Mary
Nov 23 '06 #7
Are tbFileName and tbFile Global variables and how and where is their value being set?

Mary
Hi Mary

Many thanks for your help with this. I am embaressed to admit I forgot to do the obvious first by cutting and pasting the data range I wanted. This threw up the problem in that the third column was based on merged cells in the spreadsheet so would not import. I changed the range by one row and now it works perfectly.

Thanks very much once again

ChrisD
Nov 23 '06 #8
MMcCarthy
14,534 Expert Mod 8TB
Hi Mary

Many thanks for your help with this. I am embaressed to admit I forgot to do the obvious first by cutting and pasting the data range I wanted. This threw up the problem in that the third column was based on merged cells in the spreadsheet so would not import. I changed the range by one row and now it works perfectly.

Thanks very much once again

ChrisD
Don't worry Chris

We're all done it. The nature of the programmer is to concentrate so much on the complicated stuff the simple mistakes get made.

Mary
Nov 23 '06 #9

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

Similar topics

2
by: Mr. Bungle | last post by:
When importing excel from access I am fully aware that one can import directly into a table. Can you get as specific via code or something to import data from an excel sheet to a FORM (Not Table)...
2
by: Don W. Reynolds | last post by:
Hi All, I am sent an excel spreadsheet on a daily basis. Sometimes it contains 10 rows; sometimes it contains over 5000 rows. I copy this spreadsheet into another spreadsheet and verify the...
9
by: jillandgordon | last post by:
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I get to the lst step and am told that it was not imported due to an error. ...
2
by: jereviscious | last post by:
Hi all - Last resort time. I'm importing data from a spreadsheet that I receive from one of my vendor using interop.excel. The date field in excel is entered as 4/7/2006, but when I retrieve...
0
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from...
3
by: D.Stone | last post by:
I'm trying to import an Excel spreadsheet into an existing Access table using Office 2003. Ultimately, the plan is to do it programmatically using TransferSpreadsheet, but to check that the file...
4
by: Bongard | last post by:
I have a dynamic range that I would like to use as a linked table into Access. The problem is that Access doesn't seem to want to to recognize the dynamic range when you click on "show named...
2
anoble1
by: anoble1 | last post by:
I have a button in my database that when you hit tit, it imports just 1 excel sheet and puts it in a table. Works great. I am wanting to grab 4 more excel sheets from different locations and store...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.