Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. Sub DelRandData()
  2. Dim rng As Range
  3. Dim i As Long, x As Long, y As Long
  4.  
  5. Set rng = Selection
  6.  
  7. On Error GoTo ErrHandler
  8.  
  9. Application.Calculation = xlCalculationManual
  10. Application.ScreenUpdating = False
  11.  
  12. For i = 1 To Int(rng.Cells.Count * 0.07)
  13. retry:
  14. x = WorksheetFunction.RandBetween(1, rng.Rows.Count)
  15. y = WorksheetFunction.RandBetween(1, rng.Columns.Count)
  16. If rng.Cells(x, y) <> "" Then
  17. rng.Cells(x, y).ClearContents
  18. Else
  19. GoTo retry
  20. End If
  21. Next i
  22.  
  23. Application.Calculation = xlCalculationAutomatic
  24. Application.ScreenUpdating = True
  25.  
  26. ErrHandler:
  27. Application.Calculation = xlCalculationAutomatic
  28. Application.ScreenUpdating = True
  29.  
  30. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement