It needs to find the right excel tab (July 2020 in this case), the right column, and the right date.
We can use a fixed column position for each item since Copper will always be in column B, Brass MS 58 in column D, MP 58 in column E, and Brass MS 63/37 in column F.
How do I achieve this without changing the excel format?
So for each row in your datatable - you need to first identify the month and year - from your date - in order to select the tab.
You would need to then read that sheet into a datatable without headers in order to work out which row to update.
So in your for each: WorkSheet = CDate(row.item("Date").ToString).ToString("MMM yyyy") - this will give you for example Jul 2020.
Assign your date in the format like the file: RowDate = CDate(row.item("Date").ToString).ToString("dd/ MMM/ yy")
As you know the columns for each one as you mentioned you can hard code the column to update but need to identify the row depending on the date for each metal - you can use a switch to assign the column letter:
I followed your concept and I think I got it to work. The only problem is that it is running slower than what I was expecting. I have a lot more data that I need to pass to excel than the four sample data that I previously provided. Do you mind if I send you a private message with my sample work so you can help me take a look? Maybe I did something that is causing this. Just curious to see if you know any optimization that can be done.
I just figured it out. I had an unnecessary loop (For each row in metal 2020.xlsx) inside For each row in dt_data so it was running the RowIndex logic 37 more times for each metal.