I'm having trouble getting a function to recognise defined variables from the sub that runs the function. Essentially what I'm trying to do is have a macro for each data type where all that is defined is 6 different times:
Sub F3DataSort()
zone1 = "00:26:00"
zone2 = "00:32:00"
zone3 = "00:38:00"
zone4 = "00:44:00"
zone5 = "00:50:00"
zone6 = "00:56:00"
ColumnSort
DrawGraph
End Sub
There is also a F1datasort, F2datasort, etc up to 4. Columnsort needs to use the values defined here to fill in cells with the appropriate formulas. Drawgraph can be ignored for now.
The important part of columnsort is as follows:
Function ColumnSort()
'Peak value
Range("E2").Value = "=MAX(RC[-1]:R[9993]C[-1])"
'Peak time
Range("F2").Value = "=INDEX(RC[-3]:R[9998]C[-3],MATCH(RC[-1],RC[-2]:R[9998]C[-2],0))"
'Milestone 1
Range("F5").Value = zone1
'Milestone 1 temp formula
Range("E5").Value = "=INDEX(R[-3]C[-1]:R[9995]C[-1],MATCH(RC[1],R[-3]C[-2]:R[9995]C[-2],1))"
'Milestone 2
Range("F6").Value = zone2
'Milestone 2 temp formula
Range("E6").Value = "=INDEX(R[-4]C[-1]:R[9994]C[-1],MATCH(RC[1],R[-4]C[-2]:R[9994]C[-2],1))"
'Milestone 3
Range("F7").Value = zone3
'Milestone 3 temp formula
Range("E7").Value = "=INDEX(R[-5]C[-1]:R[9993]C[-1],MATCH(RC[1],R[-5]C[-2]:R[9993]C[-2],1))"
'Milestone 4
Range("F8").Value = zone4
'Milestone 4 temp formula
Range("E8").Value = "=INDEX(R[-6]C[-1]:R[9992]C[-1],MATCH(RC[1],R[-6]C[-2]:R[9992]C[-2],1))"
'Milestone 5
Range("F9").Value = zone5
'Milestone 5 temp formula
Range("E9").Value = "=INDEX(R[-7]C[-1]:R[9991]C[-1],MATCH(RC[1],R[-7]C[-2]:R[9991]C[-2],1))"
'Milestone 6
Range("F10").Value = zone6
'Milestone 6 temp formula
Range("E10").Value = "=INDEX(R[-8]C[-1]:R[9990]C[-1],MATCH(RC[1],R[-8]C[-2]:R[9990]C[-2],1))"
End Function
This just tells it to look up what the data reading is at a particular time defined by zone1, zone2, etc. This is the kind of thing I'm going for, I'm just trying to simplify it so that as much of the code as possible need only be written once.
https://www.dropbox.com/s/13agn2zihmxzwbu/example%20for%20code.jpg
As you can probably tell, I am a total beginner for this and just winging it as I go along. I've tried searching for solutions to this but had no luck finding a situation like mine.