Delete the top 15 rows in excel with a script

Geoff Culbertson 1 Reputation point
2021-12-14T12:05:24.23+00:00

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.

Microsoft 365 and Office Development Other
Microsoft 365 and Office Excel For business Windows
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2021-12-14T15:48:16.07+00:00

    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.

    0 comments No comments

  2. Limitless Technology 39,916 Reputation points
    2021-12-15T16:10:24.17+00:00

    Hi @Geoff Culbertson

    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--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.