Hello and thank you for the help, especially since I know I am asking a lot. Hopefully someone already has code for what I need to do. I have tried a search but haven’t found anything that appears to do what I need.
I truly appreciate and help that can get me started in the right direction.
I need code that essentially is preparing excel files column header/field names for import into sql server (someone else is doing that part). The column headers currently have spaces/special characters that need to be replaced with the underscore character “_”.
I do not know how to write this type of code and there are several additional challenges.
1. I need code that will loop through several hundred of the Excel files in a file folder (folder names will vary). Each Excel file has only one sheet - Sheet1
2. For each file, loop through the first row (column headings starting in A1) and for each column heading replace any space or other special character with the underscore character – so each heading should only contain letters, numbers and the underscore
Some challenges:
The number of column headings range from roughly 90 to 140.
Some of the column headings are duplicated, (general there may be two or three duplicates, I know this is crazy but I can’t do anything about that), so for each duplicate, the second occurrence needs to be appended with a 1 (one) at the end of the name, and the third occurrence needs to be appended with a 2 (two), and so on. For example the second occurrence of xyz would be named xyz1 and the third occurrence needs to be named xyz2, etc.
There are some column headings that are blank (again I know this is crazy but I can’t do anything about this either in the hundreds of files). So the code that is looping through needs to loop through all the way to the last column heading with a value in it. For each blank column heading I want to insert a name, like Blank1, blank2, etc.
Again, thank you for any assistance that can get me started.
I’ll try to tackle the next part after I get this part done, I will need to covert the excel files to csv files, but instead to the comma delimiter, they want a pipe/stick character because some data contains commas…
I truly appreciate and help that can get me started in the right direction.
I need code that essentially is preparing excel files column header/field names for import into sql server (someone else is doing that part). The column headers currently have spaces/special characters that need to be replaced with the underscore character “_”.
I do not know how to write this type of code and there are several additional challenges.
1. I need code that will loop through several hundred of the Excel files in a file folder (folder names will vary). Each Excel file has only one sheet - Sheet1
2. For each file, loop through the first row (column headings starting in A1) and for each column heading replace any space or other special character with the underscore character – so each heading should only contain letters, numbers and the underscore
Some challenges:
The number of column headings range from roughly 90 to 140.
Some of the column headings are duplicated, (general there may be two or three duplicates, I know this is crazy but I can’t do anything about that), so for each duplicate, the second occurrence needs to be appended with a 1 (one) at the end of the name, and the third occurrence needs to be appended with a 2 (two), and so on. For example the second occurrence of xyz would be named xyz1 and the third occurrence needs to be named xyz2, etc.
There are some column headings that are blank (again I know this is crazy but I can’t do anything about this either in the hundreds of files). So the code that is looping through needs to loop through all the way to the last column heading with a value in it. For each blank column heading I want to insert a name, like Blank1, blank2, etc.
Again, thank you for any assistance that can get me started.
I’ll try to tackle the next part after I get this part done, I will need to covert the excel files to csv files, but instead to the comma delimiter, they want a pipe/stick character because some data contains commas…
Last edited: