Import N lines from source Excel file

ajocius1

Board Regular
Joined
Dec 21, 2007
Messages
111
Office Version
  1. 365
Platform
  1. Windows
My source file contains header with some relevant info followed by data table. Can I using Power Query import:
  1. Top N lines from source;
  2. Data starting from line N+1 (in a separate query).
Also, my source excel file is generated once per month, contains only one sheet, but the name of the sheet is always different (refers to invoice number). Can I use Sheet1 (as it is the only sheet in the file) instead of default usage of sheet name?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
When you use Power Query to import data, one of the first options under the HOME tab is to "Remove Rows". You can remove the top or bottom "x" rows from there.

Without seeing your data, it's hard to give much more advice than that - Power Query is very intuitive. Give it a shot and see if that works. Also, "Sheet 1" should not be an issue, but again hard to say without seeing the exact files.
 
Upvote 0
Thanks for the answer,

I did exactly that. And one step in between, which is counting number of rows. In order to tell number of rows to remove from bottom, I needed to deduct top rows from total.

Initially I was hoping that you can only import what is necessary and therefore save time, instead of loading everything and then removing what you do not need.
 
Upvote 0
In order to tell number of rows to remove from bottom, I needed to deduct top rows from total.

Did you notice that there is also a "Keep Rows" option? I'm not sure you need to count the rows - just keep the first "n" rows, and everything below is deleted from the data set. From your post, it looks like you may need two separate queries - one for keeping the top few rows, and one for keeping the rest.
 
Upvote 0

Forum statistics

Threads
1,223,634
Messages
6,173,475
Members
452,516
Latest member
archcalx

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