Alright, Ill try to explain this as best as I can first…
My program creates a dynamic table of information, Im trying to simplify some of the information by using a loop. To make it easy I will just say that the table starts on A1 and goes to (columnindex:rowindex*6) (that part is already done).
what I want it to do is to take the average of each column and put them somewhere else on the same excel sheet.
So Average(A1:A(rowindex*6)), Average(B1:B(rowindex*6)), and so on all the way up till Average((columnindex)1:columnindex(rowindex*6)
Now the tricky part….
Starting in A((rowindex*6)+5)…. So 5 rows below the table above starting in Column A….
Have it go…
Average(A), Average(B)
Average(C), Average(D)
Average(E), Average(F)
And so on until all the columns are listed…
Where I am struggling is converting columnindex to the appropriate letters as there is always 34-40 columns
I know that I would want to do something like:
i = 5
for x = 1 to x = columnindex
dim Num2Let1 as string = a=1, b=2, c=3, so on..
dim Num2Let2 as string = a=1, b=2, c=3, so on..
xlWorkSheet2.Cells((rowindex*6)+i), 1) = "Average(" & Num2Let1.ToString & cstr(1) & ":" & Num2Let1.ToString & cstr(rowindex*6))
xlWorkSheet2.Cells((rowindex*6)+i), 2) = "Average(" & Num2Let2.ToString & cstr(1) & ":" & Num2Let2.ToString & cstr(rowindex*6))
i = i + 1
x = x + 2
loop
next
If anyone could throw some advice my way, whether this is the approach that would be most conducive to my problem, or if there is an easier solution, it would be greatly appreciated.
Thanks
Here is a function that will give you the column name based on its index:
That should help you to create your average function strings.