This is not an answer. It is attempt to understand your question behind which I suspect is an interesting problem. You should copy the correct guesses about your problem from this text to your question and replace the incorrect guesses.
You cannot keep data in arrays so you must be describing the middle of the problem. I guess you have a worksheet containing the formatted data and from time-to-time you receive a CSV file of new data which is to be merged into the worksheet.
To make descriptions easier, I will use this to represent your formatted data:
Name Week Mon Tue Wed Thu Fri
John 1 5 10 12 4 3
Gwen 1 3 15 3 1 8
John 2 3 7 18 6 4
Gwen 2 9 20 4 1 7
You say the formatted names may change or be added to. Perhaps the boss decides Mon, Tue, etc. is too informal and wants the week names spelt out. Perhaps you add Saturday and Sunday and get into arguments about whether Sunday is the first or the last day of the week.
You say the column headings in the CSV file do not always matches the formatted column headings. Perhaps the CSV headings are abbreviated when the formatted ones are not. Perhaps the CSV headings are in Spanish. Perhaps there is a public holday during a rush period so John and Gwen work Tuesday to Saturday. Perhaps Friday is the Sabbath for a new member of staff so they work Sunday to Thursday.
You are thinking about using InputBox
to get the user to select the two heading sequences but I cannot see how that would work.
Firstly, you can look at the worksheet to find the desired sequence. The user does not have to select anything.
Secondly, for the user to select a name set and sequence for the CSV file means the macro must hold a list of all possible name sets and sequences. Is that possible? Since you state the CSV file may include a new heading, I would guess not.
Suppose, the two sets of headings are:
Worksheet: Name Week Mon Tue Wed Thu Fri
CSV file: Staff WoY Sun Mon Teu Wed Sat
There are different names for the Name and Week columns. There are different weekdays with the complication that Tuesday has been misspelt.
Will you have a prepared list matching the CSV file? Will you attempt to fix differences on the fly? I do not think a complete set of prepared lists is possible. The second will require some clever and complicated code for limited benefit.
I would (1) simplify the requirement and (2) have a prepared table of alternative names.
To simplify, I would require the formatted data include every possible column in advance. If a CSV file contains the previously unknown Saturday, I would require it be added before the CSV file is applied. I would not try to add "Teu" if it was not in the list.
My table of alternatives would be in a hidden worksheet and be something like this where every row defines a list of alternative names for the same column:
Name Staff Staff member
Week WoY Week of year
Mon Monday M
Tue Tuesday Tu Teu
Wed Wednesday W
Thu Thursday Th
Fri Friday F
Sat Saturday Sa St
Sun Sunday Su Sn
This table cannot handle ambiguities. Given M T W T F
, it could not deduce that the first T
is Tuesday and the second Thursday.
You can include mispellings (such as Teu
) if you wish.
I would require every column header from both the worksheet and the CSV file be in this table. Any unrecognised column header would result in a helpful message so the user could fix the worksheet, the table of alternatives or the CSV file before rerunning the macro.
It should be clear that although you may have a VBA problem I think you have a design problem first.
Good luck.