Forum Discussion
CRogers650
Aug 25, 2023Copper Contributor
Excel Visual Basics - Reading Closed .csv files & Grabbing Certain Rows
Hello everyone, I am pretty new to using VBA and was hoping someone could help me with retrieving certain information from file(s). At this moment I am trying to get Excel to read and grab informat...
nimesht
Aug 25, 2023Iron Contributor
Hi CRogers650,
Is there a unique ID column in the CSV files, which could work as primary key (only once in whole file)?
If yes, is the CSV file sorted using this unique ID column?
If yes to both, then you can use SQL Top 1 condition along with ASC/DESC order clauses to get 1st and last records.
OR, after importing the data using ADO, keep only the first and last record as below.
You can create the VBA using record macro as below.
- select the cell from the 1st record which you need to keep
- Navigate to the cell in the 2nd row using down key
- select all the cells till last record using Ctrl + Shift + down key
- deselect the last row cell using Shift + Up key
- Click Shift + Spacebar to select complete rows
- Press Del key to delete
I hope that should do it for you.
Use Like if this post helped to solve your issue and Mark as Best Response if the request can be closed.