Import Spreadsheet using a specific range

a7n9

Well-known Member
Joined
Sep 15, 2004
Messages
696
Hello All,

I'm using Transferspreadsheet Action in VBA to import a sheet, but there is a problem. There is a blank row in the between the data I want to Import and the line which I don't want. I'm attaching a snapshot. I was wondering if we could specify the range as we do in Excel using End(xlup) function.

This range would always start from "A1" and end at "E last row".

And I cannot Name the range as I expect the file to be frequently updated.

Any help is appreciated.
census.xls
ABCDEF
256254LineEndMarker(--2dashes)024990250022dashes(--)
257
258Sum+252forblankspacebetweencolumns2500
Student
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Well, I think I found the solution to this problem.
I used Excel application as object and then found out the last row, stored it in a variable and then used it to import that range using importspreadsheet function.

Here's the code
Code:
Public Sub import_wksht()
Dim oExcel As Excel.Application
Dim myExcelFile As String
myExcelFile = "C:\somtehing.xls"
Set oExcel = New Excel.Application
oExcel.Workbooks.Open FileName:=myExcelFile
'oExcel.Visible = True
Dim lastrow As Long
lastrow = oExcel.Workbooks("something").Worksheets("wksht1").Range("A65536").End(xlUp).Row
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "TP1", myExcelFile, True, "wksht1t!A1:E" & lastrow

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,899
Messages
6,162,682
Members
451,782
Latest member
LizN

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top