View Full Version : [SOLVED:] Add between 10% to 20% random to numbers in cloumn F
parscon
07-16-2021, 04:45 AM
Hi everyone
I have a List that i need add Random between 10 to 20 Percent to the value are in Column F . and must ignore blank cell and cell has character only apply in cell with number .
For Example If i have 13.5 in Column F , add 11 Percent (Between 10 to 20 Percent) will be 14.985 . Could you please help me on this .
Appreciate for all you help and effort.
Is that the current inflation percentage each day?
parscon
07-16-2021, 06:55 AM
No , It is not just it will be run for one time and important to be random mean from 10 to 20 Percent .. .between these .. my list is about 94000 row .
Paul_Hossler
07-16-2021, 08:56 AM
Fixed value and formula
Option Explicit
Sub FixedValue()
Dim r As Range, c As Range
Set r = ActiveSheet.Columns(6).SpecialCells(xlCellTypeConstants, xlNumbers)
Randomize
For Each c In r.Cells
'fixed value
'c.Offset(0, 1).Value = c.Value * (1.1 + 0.1 * Rnd)
'formula
c.Offset(0, 1).Formula = "=" & c.Address & "*(1.1+0.1*RAND())"
Next
End Sub
The result will be between 10.00000000000% and 20.99999999999% increase
Option Explicit
Sub AddToF()
Dim FArr
Dim i As Long
FArr = Intersect(Range("F1").CurrentRegion, Range("F:F")).Value
For i = 1 To UBound(FArr)
If IsNumeric(FArr(i, 1)) Then _
FArr(i, 1) = FArr(i, 1) * 1 + (Int((20 - 10 + 1) * Rnd + 10) / 100)
Next i
Range("F1").Resize(UBound(FArr, 1)) = FArr
End Sub
Example Returns, as percent additions:
10.999999940395400%
14.000000059604600%
18.000000715255700%
14.000000059604600%
15.999999642372100%
18.000000715255700%
17.000000178813900%
11.999999731779100%
15.000000596046400%
18.999999761581400%
11.999999731779100%
15.999999642372100%
15.000000596046400%
12.999999523162800%
20.000000298023200%
10.999999940395400%
17.000000178813900%
15.999999642372100%
17.000000178813900%
14.000000059604600%
12.999999523162800%
14.000000059604600%
10.000000149011600%
arnelgp
07-17-2021, 10:34 PM
copy and paste to New Module:
Public Function fn1020pct(r As Range) As Variant
Dim num As Double
fn1020pct = ""
If IsNumeric(r & "") Then
num = CDec(RandBetween(10, 20)) / CDec(100)
fn1020pct = r.Value * (1 + num)
End If
End Function
Public Function RandBetween(Optional Lowest As Long = 1, Optional Highest As Long = 9999)
' Generates a random whole number within a given range
Randomize (Timer)
RandBetween = Int(Rnd * (Highest + 1 - Lowest)) + Lowest
End Function
on the cell you want to apply the 10~20%, add this formula:
=fn1020pct(F1)
copy the formula down.
parscon
07-20-2021, 08:24 PM
Well Done and Thanks for your works and effort .
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.