Hi,
I'm quite new on VBA and need help with a problem. I will try to explain without writing a novel.
I have an excel sheet with thousands of cells filled with data.
There are groups of data where I would like to do different kinds of calculations.
I have made a lot of different vba scripts explicity for each group of cells where I am doing some calculations.
Now, in order to decrease the number of scripts and make my code more maintainable I would like to send row numbers as argument to functions called from different cells. Then I can use less scripts which will be generic.
I have those as constants. from time to time I will change the values.
I put an example here (The important thing is not what is calculated but how I can get my start & end constants to my function).
The ones listed in the example is only a minor part of my constants.
So, the constants startGrp1 etc need to go as argument startGrp and endGrp in my script.
Private Const startGrp1 = 50
Private Const endGrp1 = 137
Private Const startGrp1b = 143
Private Const endGrp1b = 230
Private Const startGrp2 = 237
Private Const endGrp2 = 258
Private Const startGrp2b = 237
Private Const endGrp2b = 265
Private Const StartCpuCol = 15
Private Const EndCpuCol = 16
Private Const CpuInst = 14
Private Const Load = 22
Function Cpu_test(cpu As Variant, startGrp As Integer, endGrp As Integer)
Dim ret As Double
Dim counter As Integer
Dim divisor As Integer
ret = 0
For counter = startGrp To endGrp
If Worksheets("mySheet1").Cells(counter, StartCpuCol).Value <= cpu Then
If Worksheets("mySheet1").Cells(counter, EndCpuCol).Value >= cpu Then
divisor = Worksheets("mySheet1").Cells(counter, CpuInst).Value
ret = ret + (Worksheets("mySheet1").Cells(counter, Load).Value) / divisor
End If
End If
Next
Cpu_test = ret
End Function
Hope someone can help :-)
Kind Regards,
Ulf
Bookmarks