I have a huge excel file(s) with different sheets. Since the next sheets and next files can look slightly different from each other there is a common header in each file to find the correct column. So I only get the information in which row the common header is (e.g. row 50 in the example below).
So the task is to look for the Value NPP and get the column index. Once I have the column index I can get the row index for a string that starts with “D.” (see below). But I dont know how to get the column index.
Obviously the value NPP or the other values like MPP can be in different columns.
To Get Col Index: (datatable.Columns.Item(“ColumnName”).Ordinal+1).ToString To Get Row Index: datatableVariable.Rows.IndexOf(datatableVariable.AsEnumerable().Where(Function(row) row(0).ToString.Contains(“yourSpecificWord”)).ToArray()(0))+1).ToString
thanks for the answers but your formulas for col index assume that I have a column name which I dont.
I only have the information in which row my common header is.
So somewhere in row 50 I have to find out in which column X the value MPP is located.
So this formula would not be correct because the column index might be different than 0.
You are right, but:
I need to find the column index without the column name. Once I have the correct column index, I can use your row index code because your code assumes that the value MPP is in column 0 which is not always the case.