joshuaholdiman
New Member
- Joined
- Oct 19, 2022
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
I use the following code for a button to pull a list of items that require (Care Of Supplies In Storage) inspection based on dates, and it works great. Is there a way to modify this code to pull a random 10% of the items on the main inventory page for monthly 10% inventory audit?
VBA Code:
Private Sub CommandButton1_Click()
Dim xRgS As Range, xRgD As Range, xCell As Range
Dim i As Long, xCol As Long, J As Long
Dim xVal As Variant
On Error Resume Next
Sheets("COSIS Report").Cells.Clear
Set xRgS = Worksheets("Inventory").Range("B:B")
If xRgS Is Nothing Then Exit Sub
Set xRgD = Worksheets("COSIS Report").Range("A2")
If xRgD Is Nothing Then Exit Sub
xCol = xRgS.Rows.Count
Set xRgS = xRgS(1)
Application.CutCopyMode = False
J = 0
For i = 1 To xCol
Set xCell = xRgS.Offset(i - 1, 0)
xVal = xCell.Value
If TypeName(xVal) = "Date" And xVal <= Date + 30 Then
xCell.EntireRow.Copy xRgD.Offset(J, 0)
J = J + 1
End If
Next
Application.CutCopyMode = True
With Range("A:A")
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False
Sheets("COSIS Report").Range("C:C").Cells.Clear
Sheets("COSIS Report").Range("D:D").Cells.Clear
Sheets("COSIS Report").Rows("1:500").RowHeight = 15
Sheets("Inventory").Range("1:1").Copy Sheets("COSIS Report").Range("1:1")
End Sub