Home |
Search |
Today's Posts |
|
#1
![]() |
|||
|
|||
![]()
I need a formula and am finding it difficult. I created a UDF to avoid
hassles with #VALUE! etc (sometimes a "?" is entered so I can't divide it), giving me trouble but am stuck on this. Imagine I have to take samples from a number of containers. The number of samples needed (every 4th container, every 20th, etc) varies according to source. There must always be a minimujm of 2 samples if the containers number more than 1. Assuming every 3rd container is to be sampled, In my UDF I have a select case with case 1 sample = 1 (this covers 1st) case 2 to number_of_containers+1 sample = 2 (this covers 1st & 4th) else It is the else bit that has me stumped. I had = total_containers/skip_rate + 1 but she no work. I find it hard because I am not mathematically inclined and the fact that the samples required change from every 3rd, 4th and up to 60th really throws me. Is there something staring me in the eye that I'm not seeing? Probably. So, given 44 containers, if I need every 3rd, how can I calculate it? The same calculation has to work with every 7th, every 11th, etc. TIA. |
#2
![]() |
|||
|
|||
![]()
One way:
You can use the \ operator, which returns an integral result Public Function NumSamples(total_containers As Long, _ skip_rate As Long) As Long Dim nTemp As Long If total_containers = 1 Then nTemp = 1 Else nTemp = Application.Max(2, _ (total_containers - 1) \ skip_rate + 1) End If NumSamples = nTemp End Function In article et.au, Mike Echo wrote: I need a formula and am finding it difficult. I created a UDF to avoid hassles with #VALUE! etc (sometimes a "?" is entered so I can't divide it), giving me trouble but am stuck on this. Imagine I have to take samples from a number of containers. The number of samples needed (every 4th container, every 20th, etc) varies according to source. There must always be a minimujm of 2 samples if the containers number more than 1. Assuming every 3rd container is to be sampled, In my UDF I have a select case with case 1 sample = 1 (this covers 1st) case 2 to number_of_containers+1 sample = 2 (this covers 1st & 4th) else It is the else bit that has me stumped. I had = total_containers/skip_rate + 1 but she no work. I find it hard because I am not mathematically inclined and the fact that the samples required change from every 3rd, 4th and up to 60th really throws me. Is there something staring me in the eye that I'm not seeing? Probably. So, given 44 containers, if I need every 3rd, how can I calculate it? The same calculation has to work with every 7th, every 11th, etc. TIA. |
#3
![]() |
|||
|
|||
![]() |
#4
![]() |
|||
|
|||
![]()
One way:
Public Function NumSamples(total_containers As Long, _ skip_rate As Long) As Long Dim nTemp As Long If total_containers <= 2 Then nTemp = total_containers Else nTemp = (total_containers - 1) \ skip_rate + 1 - _ ((total_containers - 1) Mod skip_rate 0) End If NumSamples = nTemp End Function In article et.au, Mike Echo wrote: This made me realise I forgot one condition - if the total_containers/skip_rate has a remainder then one more container needs to be sampled (as the "final" container). If skip=3 and containers = 11 or 12 then sample = 5 (1,4,7,10,last). I tried to add a line using MOD but I messed it up. Any idea? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I use a check box to accept a calculation | Excel Discussion (Misc queries) | |||
Auto Calculation Automatically Turns Off???? | Excel Discussion (Misc queries) | |||
Help with calculation | Excel Worksheet Functions | |||
Help on automatically ending a calculation | Excel Worksheet Functions | |||
time-clock calculation | Excel Worksheet Functions |