L
Legacy 218534
Guest
I have been googling for a couple of hours now, and would like some help. I am looking to shorten this code (I have 95 variables):
NONTEMP(x) stores data column header names based on a separate sheet that is setup prior to running. This code opens a data file, then searches for these header names. When if finds a header name it stores the column location for later use. eg:
I realize it would be extremely easy to just make NONTEMP(1 to 95, 1 to 2) and store the header names and location values all in the single array.
BUT calculations would look like:
However, this makes the code very hard to debug for anyone in my office who isn't me. I am doing all of this inside a Sub in a module. I have tried using CallByName, but none of my code is in a Class module, and I don't really understand what I'm doing with the function.
The header names stored in NONTEMP(x) are the same as the variable names I would like to be using. It would be nice if I could do something like this:
Where NONTEMP(x) is a string value containing the column header to search for, and the variable name that is used later in the equations. Please help!
Thanks,
Tim
Code:
For j = 1 To icolumncount[INDENT]Select Case Cells(header_row, j)[/INDENT]
[INDENT=2]Case NONTEMP(1): ModeNumber = j[/INDENT]
[INDENT=2]Case NONTEMP(2): TestNumber = j[/INDENT]
[INDENT=2]Case NONTEMP(3): DataNumber = j[/INDENT]
[INDENT=2]Case NONTEMP(4): LoopNumber = j[/INDENT]
[INDENT=2]Case NONTEMP(5): StageNumber = j[/INDENT]
[INDENT=2]Case NONTEMP(6): CycleNumber = j[/INDENT]
[INDENT=2]Case NONTEMP(7): speed = j[/INDENT]
[INDENT=2]Case NONTEMP(8): Torque = j[/INDENT]
[INDENT=2]Case NONTEMP(9): HP = j[/INDENT]
[INDENT=2]Case NONTEMP(10): throttle = j[/INDENT]
[INDENT=2]Case NONTEMP(11): p_baro = j[/INDENT]
[INDENT=2]Case NONTEMP(12): g_air = j[/INDENT]
[INDENT=2]Case NONTEMP(13): g_fuel = j[/INDENT]
[INDENT=2]Case NONTEMP(14): fuel_tot = j[/INDENT]
[INDENT=2]Case NONTEMP(15): humidity = j
'continues until....
Case NONTEMP(95): FSN2 = j[/INDENT]
[INDENT]End Select[/INDENT]
Next j
NONTEMP(x) stores data column header names based on a separate sheet that is setup prior to running. This code opens a data file, then searches for these header names. When if finds a header name it stores the column location for later use. eg:
Code:
[LEFT][INDENT]For x = 1 to irowcount[/INDENT]
[INDENT=2]'calculate fuel flow: g_exhaust = g_air + g_fuel[/INDENT]
[INDENT=2]Cells(x, g_exhaust) = Cells(x, g_air)+Cells(x, g_fuel)[/INDENT]
[INDENT]Next x[/INDENT]
[/LEFT]
I realize it would be extremely easy to just make NONTEMP(1 to 95, 1 to 2) and store the header names and location values all in the single array.
Code:
For j = 1 To icolumncount[INDENT]For x = 1 to 95[/INDENT]
Select Case Cells(header_row, j)
Case NONTEMP(x,1): NONTEMP(x,2) = j
End Select[INDENT]Next x[/INDENT]
Next j
BUT calculations would look like:
Code:
For x = 1 to irowcount[INDENT]'calculate fuel flow: g_exhaust = g_air + g_fuel
Cells(x, g_exh) = Cells(x, NONTEMP(13, 2)) + Cells(x, NONTEMP(12, 2))[/INDENT]
However, this makes the code very hard to debug for anyone in my office who isn't me. I am doing all of this inside a Sub in a module. I have tried using CallByName, but none of my code is in a Class module, and I don't really understand what I'm doing with the function.
The header names stored in NONTEMP(x) are the same as the variable names I would like to be using. It would be nice if I could do something like this:
Code:
For j = 1 To icolumncount[INDENT]For x = 1 to 95[/INDENT]
Select Case Cells(header_row, j)
Case NONTEMP(x): Set Variable(NONTEMP(x)) = j
End Select[INDENT]Next x[/INDENT]
Next j
Where NONTEMP(x) is a string value containing the column header to search for, and the variable name that is used later in the equations. Please help!
Thanks,
Tim