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

Importing dynamic range into Access

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 ranges" in
the Link Spreadsheet wizard. The reason I want to use a dynamic range
is because when the data in my excel spreadsheet changes the linked
table will import blank rows that were previously used from the bottom
of the spreadsheet. I can't figure out how to get rid of these extra
rows without using an additional query to filter on the blank cells.

Any ideas?

Thanks,
Brian

Sep 5 '07 #1
4 5433
"Bongard" <b.*******@gmail.comwrote in message
news:11*********************@d55g2000hsg.googlegro ups.com...
>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 ranges" in
the Link Spreadsheet wizard. The reason I want to use a dynamic range
is because when the data in my excel spreadsheet changes the linked
table will import blank rows that were previously used from the bottom
of the spreadsheet. I can't figure out how to get rid of these extra
rows without using an additional query to filter on the blank cells.

Any ideas?

Thanks,
Brian
In Excel, select all the cells you wish in your 'table', then name the range
by typing it into the cell reference box (it will currently be showing D16
or something). Press Return - this is important because Excel will 'forget'
your name if you don't.

Now you can link to the range from Access.

Sep 5 '07 #2
Thanks for the response Stuart but this is not going to work. I have
created a dynamic range (expands and contracts depending on data size)
to allow for the constant changing of data within the Excel file. If I
just use a typical named range it will not change size to include or
exclude cells as necessary.

Sep 5 '07 #3
Bongard wrote:
Thanks for the response Stuart but this is not going to work. I have
created a dynamic range (expands and contracts depending on data size)
to allow for the constant changing of data within the Excel file. If I
just use a typical named range it will not change size to include or
exclude cells as necessary.
Maybe ask in a microsoft.public.excel newsgroup for some vba code to
define dynamic ranges.

You may find some things on dynamic ranges in google, such as
http://groups.google.com/group/micro...3035e1d472421e

Maybe there's some answers at google or the Excel newsgroups.

Would it not be possible to create a named range on the fly and then do
the link? Perhaps delete a named range, recreate dynamic, save the
coordinates as a new range, then import?

Sep 5 '07 #4
Hi Bongard,

This is a problem that I have never found an exact solution to, but I
can give you a pragmatic one. If your dynamic named range is not
expanding to extra columns then this will work:

1/ Select all the columns in Excel (eg: A B C D E.....)

2/ Type in a name for the 'fixed' range. This is going to refer to the
same cells as the dynamic at the same time that the dynamic range is
referring to them.

3/ Using ADO to connect to the spreadsheet, you can then import the
data into a local table as follows.....

Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source = " & FileName & "; Extended
Properties = Excel 8.0;"
.Open
End With

Dim rs as ADODB.Recordset
Set rs = New ADODB.Recordset
SQL = "select * from [" & NamedRangeName & "] where ColumnName <>
null"

With rs
.CursorLocation = adUseClient
.Open SQL, cnn, adOpenForwardOnly, adLockReadOnly, adCmdText
.ActiveConnection = Nothing
End With

cnn.Close
Set cnn = Nothing

Dim db As DAO.Database
Set db = CurrentDb

Dim DRS As DAO.Recordset
Set DRS = db.OpenRecordset("RawImport")

Dim exists As Boolean
exists = False

Dim adoFLD As ADODB.Field
Dim daoFLD As DAO.Field

Do Until rs.EOF
DRS.AddNew
For Each adoFLD In rs.Fields
For Each daoFLD In DRS.Fields
If adoFLD.Name = daoFLD.Name Then
DRS(daoFLD.Name) = rs.Fields.Item(adoFLD.Name).Value
End If
Next
Next
DRS.Update
rs.MoveNext
Loop

You can obviously set up some routines in there to check the records
in the 'rawimport' table to see if the records already exists. Once
the data is in a local table you can pretty much do with it what you
like.

The key here is that the number of columns in the source Excel
spreadsheet cant change. If you add a new column to the spreadsheet
then there must be a matching field added to the access table to
receive the data or it will be missed. You shouldnt get any blank
records here because the SQL select statement used to rip the data
from the spreadsheets named range specifies a column of your choosing
to not be null, so a blank wont be imported. Lastly, make sure your
data types match and that the field in Access has enough size to
accomodate the incoming Excel data - really watch for this with text
fields.

I hope that this helps you out.

Cheers

The Frog

Sep 7 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
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. ...
7
by: robert d via AccessMonster.com | last post by:
I just imported 62000 rows twice from Excel. In my import routine, I create a holding table and then validate the data prior to committing to the main table. The holding table is created in the...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
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...
5
by: Grubsy4u | last post by:
Hi all, My name is Daniel Iam trying to learn visual basic and I have been having problems building a marco in Access 2003 that will allow me to extract data from my Excel 2003 spreadsheet into my...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.