LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 172
Default Import to the next blank row

I'm using this code to import data from a specific file along with copying
some formulas in my worksheet. The way it works is that it imports starting
with the cell I've selected and then fills the rows below that. Since this
will be a daily import I'm trying to find a way that it will automatically
import the data to the next blank row instead of me having to select the cell
where the import should start. How would I go about modifying this code to do
that?

Sub TestReadDataFromWorkbook()
' fills data from a closed workbook in at the active cell
Application.Calculation = xlManual
Dim tArray As Variant, r As Long, c As Long
tArray = ReadDataFromWorkbook("C:\Shipped.xls", "A2:I100")
For r = LBound(tArray, 2) To UBound(tArray, 2)
For c = LBound(tArray, 1) To UBound(tArray, 1)
ActiveCell.Offset(r, c).Formula = tArray(c, r)
Next c
Next r

copydown
Application.Calculation = xlAutomatic
End Sub

Private Function ReadDataFromWorkbook(SourceFile As String, SourceRange As
String) As Variant

Dim dbConnection As ADODB.Connection, rs As ADODB.Recordset
Dim dbConnectionString As String
dbConnectionString = "DRIVER={Microsoft Excel Driver
(*.xls)};ReadOnly=1;DBQ=" & SourceFile
Set dbConnection = New ADODB.Connection
On Error GoTo InvalidInput
dbConnection.Open dbConnectionString ' open the database connection
Set rs = dbConnection.Execute("[" & SourceRange & "]")
On Error GoTo 0
ReadDataFromWorkbook = rs.GetRows ' returns a two dim array with all
records in rs
rs.Close
dbConnection.Close ' close the database connection
Set rs = Nothing
Set dbConnection = Nothing
On Error GoTo 0
Exit Function
InvalidInput:
MsgBox "The source file or source range is invalid!", vbExclamation,
"Get data from closed workbook"
Set rs = Nothing
Set dbConnection = Nothing
End Function
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import blank date into excel tulsagirl Excel Discussion (Misc queries) 3 January 3rd 08 10:50 PM
Import csv file - blank lines inserted Dave Peterson Excel Discussion (Misc queries) 0 February 21st 07 01:56 AM
Text File Import leaves a blank row after each line R Kapoor Setting up and Configuration of Excel 0 January 8th 06 02:07 PM
Excel Blank Value Import vgurusa Excel Discussion (Misc queries) 1 October 14th 05 05:20 AM
Import - blank cell problem. Domingos Excel Worksheet Functions 1 January 24th 05 03:26 PM


All times are GMT +1. The time now is 12:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"