I have found a lot of example of how to use a variable for the row but can't find anything much on using a variable to select the column.
I have this that works (assigns average from another worksheet, to MyValue, in the current worksheet):
This works but has hardcoded range
MyValue = WorksheetFunction.Average(Range("'MyFile.csv'!E2:E100"))
But I want to use a variable in range. If I was using the variable for the row, it would be easy. I could just use:
MyValue = WorksheetFunction.Average(Range("'MyFile.csv'!E2:E" & SomeVar))
But my problem is, I need to use the variable for the column. I have tried cell(r, c) for the range but can't get it to work. I'm sure it's just how I'm using it. I would expect to use cell(2,c) for the E2 part and/or cell(100,c) for the E100 part, where 'c' is a variable. But it's not working.
I tried:
MyValue = WorksheetFunction.Average(Range("'MyFile.csv'!" & cells(2,c) & "," & cells(100,c))), where 'c' is a variable, but this doesn't work.
Can someone show me how the bolded line above would be modified to use a variable to change the column value (i.e. to increment from 'C' to 'E' or 'Z' or any column)? The solution also needs to be able to use a filename, because the data is in a different file.
Bookmarks