question

GeoffCulbertson-3860 avatar image
0 Votes"
GeoffCulbertson-3860 asked LimitlessTechnology-2700 answered

Delete the top 15 rows in excel with a script

I would like to automate deleting the top 15 rows of and Excel sheet I download every night called report.xlsx.

Row 16 is where the info I need begins in the actual file. So the info runs from A - AB in the columns and I want to remove that and row 1 - 15. I believe this can be done using a PowerShell script so I can automate it to run when the file downloads and 815 PM overnight. Thanks for any info that could guide me to a solution.

windows-server-powershelloffice-excel-itprooffice-scripts-excel-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Are you downloading an XSLX file or a CSV file?

If it's XSLX I'd use the ImportExcel powershell module. But I don't understand what you mean when you say you want to remove the "A - AB". Aren't those the column names?

If it's a CSV file and you want to remove the column headers and the first 15 rows it's probably as easy as:

 get-content downloadedfile | Select-Object -Skip 16 | Out-File newfile

. . . and then remove the downloaded file.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hi @GeoffCulbertson-3860

You can construct a concatenated string containing all of the rows as you run through the Range.Find loop. Use that to define the Range object with the Range.EntireRow property to .Delete the rows in Excel.

Range("A2, A4, A10, A19").EntireRow.Delete

Hope this resolves your Query!!




--If the reply is helpful, please Upvote and Accept it as an answer--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.