Home

Searching Table Array/ Reading CSV file

%3CLINGO-SUB%20id%3D%22lingo-sub-1109493%22%20slang%3D%22en-US%22%3ESearching%20Table%20Array%2F%20Reading%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1109493%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CDIV%3EI'm%20looking%20for%20some%20help%20both%20on%20best%20approach%20and%20method%20on%20the%20below%20-%20sorry%20for%20the%20long%20description!%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3ESituation%3C%2FDIV%3E%3CDIV%3EThe%20situation%20is%20that%20I%20work%20as%20a%20contractor%20and%20do%20my%20own%20payroll.%26nbsp%3B%20The%20Revenue%20issue%20a%20CSV%20file%20annually%20with%2039%20values%20for%20tax%20allowances%20etc.%26nbsp%3B%20I%20use%20Excel%20spreadsheets%20for%20my%20payslips%20and%20pay%20myself%20monthly.%20Each%20year%2C%20I%20copy%20in%20the%20content%20of%20the%20Revenue%20CSV%20file%20into%20my%20January%20spreadsheet%20and%20use%20it's%20content%20in%20that%20to%20calculate%20the%20payslip.%20The%20February%20spreadsheet%20and%20onward%20look%20back%20at%20the%20previous%20files%20to%20handle%20the%20cumulative%20allowances.%20Once%20set%20up%2C%20this%20has%20worked%20fine%20for%20me%20for%20the%20last%20few%20years.%20This%20year%20the%20file%20includes%20additional%20fields%20(not%20added%20at%20the%20end)%20so%20my%20use%20of%20HLOOKUP%20as%20it%20stands%26nbsp%3Bwill%20not%20work.%26nbsp%3B%20I%20could%20just%20change%20the%20names%20of%20the%26nbsp%3BColumn%20headers%20so%20the%20right%20data%20is%20found%20but%20my%20concern%20is%20that%20this%20leaves%20me%20always%20changing%20it%20hard-coded%20whenever%20they%20change%20the%20layout.%26nbsp%3B%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EThe%20CSV%20file%20contains%204%20rows%20with%20first%20and%20third%20rows%20being%20headers%20for%20the%20second%20and%20fourth%20rows.%26nbsp%3B%20The%20file%20when%20read%20in%2C%20has%206%20columns%20in%20row%201%20and%202%20and%2033%20columns%20in%20rows%203%20and%204.%20In%20my%20payslip%20file%20as%20it%20stands%2C%20I%20copy%20in%20this%20data%20on%20a%20separate%20sheet%20and%20it%20is%20a%20table%20array%20above%20which%20I%20have%20a%20row%20with%20fixed%20headings%20that%20I%20use%20with%20HLOOKUP%20and%20then%20select%20the%20value%20in%20row%20(2%20or%204)%20I%20need.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EDesired%20Result%3C%2FDIV%3E%3CDIV%3EI'd%20like%20to%20be%20able%20to%20make%20it%20such%20that%20it%20can%20handle%20future%20changes%20in%20the%20CSV%20file%20where%20headings%20and%20their%20values%20may%20change%20location%2F%20layout%20again.%20I%20was%20thinking%20that%20it%20would%20be%20good%20to%20be%20able%20to%20search%20the%20table%20array%20to%20find%20the%20appropriate%20header%20(on%20either%20row%202%20or%204%20of%20the%20Table%20array)%20and%20select%20the%20value%20beneath.%3CBR%20%2F%3E%3CDIV%3E%3CDIV%20class%3D%22gmail_signature%22%3EThe%20headings%20(either%20on%20Row%201%20or%20Row%203)%20are%20terms%20like%20the%20below%20with%20the%20actual%20value%20in%20the%20cell%20beneath%20each%20one%20(either%20on%20Row%202%20or%20Row%204).%20Some%20values%20are%20blank.%3C%2FDIV%3E%3CDIV%20class%3D%22gmail_signature%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22gmail_signature%22%3E%3CTABLE%20border%3D%220%22%20cellspacing%3D%220%22%20cellpadding%3D%220%22%3E%3CTBODY%3E%3CTR%3E%3CTD%3EagentTain%3C%2FTD%3E%3CTD%3EtaxYear%3C%2FTD%3E%3CTD%3EtotalRPNCount%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E2020%3C%2FTD%3E%3CTD%3E1%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EemploymentID%3C%2FTD%3E%3CTD%3EemploymentCessationDate%3C%2FTD%3E%3CTD%3ErpnIssueDate%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E1%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E01%2F12%2F2019%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FDIV%3E%3CDIV%20class%3D%22gmail_signature%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22gmail_signature%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22gmail_signature%22%3EOn%20approach%2C%20is%20it%20best%20to%20try%20and%20pursue%20a%20good%20method%20to%20find%20the%20headers%20and%20their%20values%20or%20is%20there%20a%20better%20way%20altogether%20to%20handle%20reading%20the%20data%20from%20the%20CSV%20file%3F%20I've%20spent%20a%20while%20looking%20at%20Match%20and%20Index%20but%20the%20point%20is%20that%20the%20column%20with%20the%20header%20and%20the%20associated%20value%20is%20subject%20to%20change%20though%20it%20is%20likely%20that%20the%20header%20row%20will%20always%20be%20either%20row%201%20or%203%20(with%20associated%20data%20on%20row%202%20or%204).%3C%2FDIV%3E%3CDIV%20class%3D%22gmail_signature%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22gmail_signature%22%3EAll%20advice%20appreciated%2C%20thanks%20a%20lot.%3C%2FDIV%3E%3CDIV%20class%3D%22gmail_signature%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1109493%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1110163%22%20slang%3D%22en-US%22%3ERe%3A%20Searching%20Table%20Array%2F%20Reading%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1110163%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F519084%22%20target%3D%22_blank%22%3E%40ACreaner%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20few%20methods.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1110297%22%20slang%3D%22en-US%22%3ERe%3A%20Searching%20Table%20Array%2F%20Reading%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1110297%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F519084%22%20target%3D%22_blank%22%3E%40ACreaner%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFirst%2C%20I%20commend%20you%20for%20doing%20your%20own%20payroll.%20Back%20in%20the%2070s%2C%20before%20Excel%20even%20existed%2C%20I%20was%20using%20one%20of%20the%20precursor%20spreadsheets%20(just%20for%20fun%2C%20mind%20you)%20to%20do%20my%20own%20taxes.%20And%20that's%20when%20I%20learned%20the%20benefits%20of%20creating%20a%20tax%20table%2C%20having%20the%20cutoffs%20for%20each%20income%20level%20and%20associated%20tax%20percent%20etc.%2C%20all%20there%2C%20so%20I%20could%20do%20%22what-if%22%20analyses%20based%20on%20different%20income%20levels%2C%20and%20so%20forth.%20It%20was%20fun%2C%20but%20over%20time%20I%20realized%20I'd%20learned%20what%20I%20could%2C%20and%20my%20income%20got%20more%20complicated%2C%20so%20I%20moved%20to%20tax%20packages.%20My%20point%20is%20not%20that%20you%20should%20do%20that%3B%20rather%2C%20I'm%20just%20saying%20I%20appreciate%20how%20your%20goal%20is%20to%20have%20a%20workable%20table%20that%20you%20can%20refer%20to%20using%20HLOOKUP%20or%20INDEX%20and%20MATCH....%20You%20are%20being%20wise%20to%20avoid%20hard-coding%20as%20much%20as%20possible.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20said%2C%20my%20career%20also%20included%20a%20stint%20as%20the%20director%20of%20the%20HR%20and%20Payroll%20database%20of%20a%20major%20corporation%2C%20and%20during%20that%20time%20I%20extended%20my%20learning%20of%20the%20value%20of%20business%20tables%2C%20not%20only%20to%20avoid%20hard-coding%20data%20that%20can%20change%20from%20year%20to%20year%2C%20but%20also%20to%20help%20make%20SQL%20queries%20legible%2Funderstandable.%20That%20applies%20here%2C%20in%20the%20sense%20that%20you%20want%20your%20Excel%20formulas%20to%20be%20things%20you%20can%20make%20sense%20of.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAll%20of%20which%20leads%20me%20to%20wonder%20if%20you%20wouldn't%20benefit%20from%20taking%20that%20CSV%20file%20you%20get%20from%20Revenue%20sources%20and%20converting%20it%20(once%20each%20year)%20to%20a%20table%20of%20your%20own%20design%2C%20a%20table%20with%20only%20one%20header%20row%20instead%20of%20two%2C%20and%20a%20table%20with%20headers%20that%20are%20clear.%20You%20could%20even%20use%20HLOOKUP%20or%20whatever%20to%20do%20that%20conversion%2C%20so%20it%20would%20be%20consistent%20so%20long%20as%20they%20were%20consistent%20from%20year%20to%20year%3B%20changing%20it%20only%20when%20they%20changed.%20But%20YOU%20would%20have%20a%20single%20table%20that%20conformed%20to%20good%20Excel%20principles%20(single%20header%20row)%2C%20and%20could%20even%20then%20use%20the%20Name....Create%20capability%20to%20assign%20names%20to%20the%20various%20cells%20from%20that%20Revenue%20table....and%20your%20formulas%20would%20then%20be%20intelligible.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20asked%20for%20any%2Fall%20advice%2C%20so%20I%20thought%20I'd%20throw%20those%20thoughts%20into%20the%20hopper.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you'd%20like%20to%20pursue%20further....I'd%20be%20interested%20in%20seeing%20what%20that%20CSV%20file%20looks%20like%20in%20its%20entirety.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hi,

I'm looking for some help both on best approach and method on the below - sorry for the long description!
 
Situation
The situation is that I work as a contractor and do my own payroll.  The Revenue issue a CSV file annually with 39 values for tax allowances etc.  I use Excel spreadsheets for my payslips and pay myself monthly. Each year, I copy in the content of the Revenue CSV file into my January spreadsheet and use it's content in that to calculate the payslip. The February spreadsheet and onward look back at the previous files to handle the cumulative allowances. Once set up, this has worked fine for me for the last few years. This year the file includes additional fields (not added at the end) so my use of HLOOKUP as it stands will not work.  I could just change the names of the Column headers so the right data is found but my concern is that this leaves me always changing it hard-coded whenever they change the layout.  
The CSV file contains 4 rows with first and third rows being headers for the second and fourth rows.  The file when read in, has 6 columns in row 1 and 2 and 33 columns in rows 3 and 4. In my payslip file as it stands, I copy in this data on a separate sheet and it is a table array above which I have a row with fixed headings that I use with HLOOKUP and then select the value in row (2 or 4) I need.
 
Desired Result
I'd like to be able to make it such that it can handle future changes in the CSV file where headings and their values may change location/ layout again. I was thinking that it would be good to be able to search the table array to find the appropriate header (on either row 2 or 4 of the Table array) and select the value beneath.
The headings (either on Row 1 or Row 3) are terms like the below with the actual value in the cell beneath each one (either on Row 2 or Row 4). Some values are blank.
 
agentTaintaxYeartotalRPNCount
 20201
employmentIDemploymentCessationDaterpnIssueDate
1 01/12/2019
 
 
On approach, is it best to try and pursue a good method to find the headers and their values or is there a better way altogether to handle reading the data from the CSV file? I've spent a while looking at Match and Index but the point is that the column with the header and the associated value is subject to change though it is likely that the header row will always be either row 1 or 3 (with associated data on row 2 or 4).
 
All advice appreciated, thanks a lot.
 
2 Replies
Highlighted

@ACreaner 

A few methods.

Highlighted

@ACreaner 

First, I commend you for doing your own payroll. Back in the 70s, before Excel even existed, I was using one of the precursor spreadsheets (just for fun, mind you) to do my own taxes. And that's when I learned the benefits of creating a tax table, having the cutoffs for each income level and associated tax percent etc., all there, so I could do "what-if" analyses based on different income levels, and so forth. It was fun, but over time I realized I'd learned what I could, and my income got more complicated, so I moved to tax packages. My point is not that you should do that; rather, I'm just saying I appreciate how your goal is to have a workable table that you can refer to using HLOOKUP or INDEX and MATCH.... You are being wise to avoid hard-coding as much as possible.

 

That said, my career also included a stint as the director of the HR and Payroll database of a major corporation, and during that time I extended my learning of the value of business tables, not only to avoid hard-coding data that can change from year to year, but also to help make SQL queries legible/understandable. That applies here, in the sense that you want your Excel formulas to be things you can make sense of.

 

All of which leads me to wonder if you wouldn't benefit from taking that CSV file you get from Revenue sources and converting it (once each year) to a table of your own design, a table with only one header row instead of two, and a table with headers that are clear. You could even use HLOOKUP or whatever to do that conversion, so it would be consistent so long as they were consistent from year to year; changing it only when they changed. But YOU would have a single table that conformed to good Excel principles (single header row), and could even then use the Name....Create capability to assign names to the various cells from that Revenue table....and your formulas would then be intelligible.

 

You asked for any/all advice, so I thought I'd throw those thoughts into the hopper.

 

If you'd like to pursue further....I'd be interested in seeing what that CSV file looks like in its entirety.