jUStPunkin
Board Regular
- Joined
- Mar 23, 2009
- Messages
- 67
I have a cell, number of collection devices. Based on that number of collection devices, I'm going to have a number of sections between those devices.
If the number of devices is 5, for example, I'm going to have sections 1, 2, 3, 2, 1 (where 1 is the same as 1, 2 is the same as 2, 3 is unique)
If the number of devices is 6, for example, I'm going to have sections 1, 2, 3, 3, 2, 1 (where 1 is the same as 1, 2 is the same as 2 and 3 is the same as 3)
I then do a variety of calculations based on a number for each of those sections.
The trouble I'm having is I need to do a sum on those calculations. So I'll have a column of numbers, and I need to sum 1*2, 2*2 3*1; or 1*2, 2*2, 3*2.
I know that if the number of devices is odd; it will be 1*2, 2*2 3*1
If the number of devices is even, it will be 1*2, 2*2, 3*2.
And, to add further complexity; the number of devices could be anywhere between 2 and 20.
I'm trying to be as clear as possible, but I'm not sure if it's clear. In the screenshot, the highlighted number is the number of devices.
For the blue numbers, which are inputs, I want to be able to enter only half of them, and then add them based on whether the number of devices is odd or even, if it is even, you double all the numbers, if it's odd, you double all but the last number.
What I'm thinking I might have to do is something like (and I am not sure my syntax is correct), with just multiple cases. I'm just wondering if there is an easier, shorter way to do this?
If the number of devices is 5, for example, I'm going to have sections 1, 2, 3, 2, 1 (where 1 is the same as 1, 2 is the same as 2, 3 is unique)
If the number of devices is 6, for example, I'm going to have sections 1, 2, 3, 3, 2, 1 (where 1 is the same as 1, 2 is the same as 2 and 3 is the same as 3)
I then do a variety of calculations based on a number for each of those sections.
The trouble I'm having is I need to do a sum on those calculations. So I'll have a column of numbers, and I need to sum 1*2, 2*2 3*1; or 1*2, 2*2, 3*2.
I know that if the number of devices is odd; it will be 1*2, 2*2 3*1
If the number of devices is even, it will be 1*2, 2*2, 3*2.
And, to add further complexity; the number of devices could be anywhere between 2 and 20.
I'm trying to be as clear as possible, but I'm not sure if it's clear. In the screenshot, the highlighted number is the number of devices.
For the blue numbers, which are inputs, I want to be able to enter only half of them, and then add them based on whether the number of devices is odd or even, if it is even, you double all the numbers, if it's odd, you double all but the last number.
What I'm thinking I might have to do is something like (and I am not sure my syntax is correct), with just multiple cases. I'm just wondering if there is an easier, shorter way to do this?
VBA Code:
Public Sub NumberOfDevices()
Dim devices As Integer, result As Integer
devices = Range("b8").Value
Select Case devices
Case Is = 3
result = Sum(("A20"), ("A20"), ("A21"))
Case Is = 4
result = Sum(("A20"), ("A20"), ("A21"), ("A21"))
End Sub