hartless43
New Member
- Joined
- Dec 28, 2022
- Messages
- 33
- Office Version
- 365
- Platform
- Windows
In the following code I found elsewhere and, in the line, "For i = 1 To Int(Rng.Cells.Count * 0.45) I would like to replace the 0.45 with a value of a cell which in my case is Range("L2"). This code will remove a percentage of numbers from a range but here you have to manually write in each percentage.
Thats it and sure someone can figure this out for me.
Thanks
Jerry, a senior citizen
VBA Code:
[
Sub RemovePercentage()
Dim Rng As Range
Dim i As Long, x As Long, y As Long
Set Rng = Range("B2:J10")
On Error GoTo ErrHandler
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = 1 To Int(Rng.Cells.Count * 0.45)
retry:
x = WorksheetFunction.RandBetween(1, Rng.Rows.Count)
y = WorksheetFunction.RandBetween(1, Rng.Columns.Count)
If Rng.Cells(x, y) <> "" Then
Rng.Cells(x, y).ClearContents
Else
GoTo retry
End If
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
ErrHandler:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Thanks
Jerry, a senior citizen
Last edited by a moderator: