RickB75 Posted June 6, 2014 Posted June 6, 2014 (edited) Guys, Just a quick question. I'm drawing blank on how to get the column number after using ExcelReadSheetToArray. I have the header columns set to specific names in different workbooks in excel. example: Vin, ID, Year, etc... In some workbooks the vin column could be column 3 and some workbooks it could be in column 7. I know how to do an array search and find the string "Vin" but for the life of me I can't figure out how to get the column number after I find the string. I'm sure this is simple but I'm drawing a complete blank right now! Should I build a loop with a counter and after it finds the string use the position as the Column number? Is there an easier way than building a loop. A simple function to return the column number in the array. Edited June 6, 2014 by RickB75
water Posted June 6, 2014 Posted June 6, 2014 I'm not sure I fully understand the problem. But let me give it a try: An Excel Worksheet consists of rows and columns starting with index 1 for columns and rows. An array consists of rows and columns starting with index 0 or 1 (if the row/column count is returned in row 0) for rows and index 0 for columns. So to map the column index of the array to the column number of Excel you simply add 1 to the array index. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
RickB75 Posted June 6, 2014 Author Posted June 6, 2014 (edited) Water, Thanks for your reply. I apologize for my post sounding confusing. This is what my goal is. I have multiple excel workbooks with vehicle data in the workbooks. The header (row #1) is dedicated for the vehicle info like Vin #, Make, Model, Trim, etc. In some workbooks the Vin # column could be column 3. In other workbooks it could be column 7. What I'm wanting to do is write a script that can read multiple layouts of different workbooks using the header data as a way to identify the data in the column. Then, I can do a ArraySearch for the word "Vin #" (I know it will show in position 1 because it's always on the 1st row. It's the column number that will vary) in any one of the workbooks and once I find it, I will know what column all the Vin #'s are in, then I can use the function ExcelReadArray and pass it the column number to read, to get all the Vin #'s in that column. I guess my main question is can I use a function like ArraySearch to return the column number and the position or do I need to build a loop and use a counter. It seems like I could use ArraySearch and it return the column and position. I just don't know how to get the column number using ArraySearch. I can get the position just not the column number Edited June 6, 2014 by RickB75
water Posted June 6, 2014 Posted June 6, 2014 I would read row 1 into an array and then loop through the elements to search for "Vin #". My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
RickB75 Posted June 10, 2014 Author Posted June 10, 2014 Ok, this is what I've found to be the easiest and simplest way for me. Instead of using ExcelReadSheetToArray, I'm using ExcelReadArray and specifying the row number to read and the number of columns to read along with the direction (up or down). This function takes each cells data in the row and places it into its own position in the array. Using ExcelReadSheetToArray, it placed the entire row of data into a single position in the array. Now when I use ArraySearch for my string, It returns the position the string is located in (basically the column number I'm looking for). No loops. That would be my next attempt to get the column number if this method didn't work. Thanks for your advice / help Water.
water Posted June 11, 2014 Posted June 11, 2014 Glad to be of service My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now