Is it possible to write the following code in VBA Excel 2016 more briefly?
Select Case NemberOfProduct(i)
Case 1
CounterPlot(1) = CounterPlot(1) + 1
SumPureRate(1) = SumPureRate(1) + H(i)
Case 2
CounterPlot(2) = CounterPlot(2) + 1
SumPureRate(2) = SumPureRate(2) + H(i)
Case 3
CounterPlot(3) = CounterPlot(3) + 1
SumPureRate(3) = SumPureRate(3) + H(i)
.
.
Case 12
CounterPlot(12) = CounterPlot(12) + 1
SumPureRate(12) = SumPureRate(12) + H(i)
End Select
>Solution :
You could either manualy use NemberOfProduct(i) expresion as value.
So your whole select case could be replaced with
CounterPlot(NemberOfProduct(i)) = CounterPlot(NemberOfProduct(i)) + 1
SumPureRate(NemberOfProduct(i)) = SumPureRate(NemberOfProduct(i)) + H(i)
Or even more simplify it by storing NemberOfProduct(i) inside variable and then use it.
Dim n as Integer
n = NemberOfProduct(i)
CounterPlot(n) = CounterPlot(n) + 1
SumPureRate(n) = SumPureRate(n) + H(i)