Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub DelRandData()
- Dim rng As Range
- Dim i As Long, x As Long, y As Long
- Set rng = Selection
- On Error GoTo ErrHandler
- Application.Calculation = xlCalculationManual
- Application.ScreenUpdating = False
- For i = 1 To Int(rng.Cells.Count * 0.07)
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement