Pulling random 10% into another worksheet for inventory management

joshuaholdiman

New Member
Joined
Oct 19, 2022
Messages
1
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,224,814
Messages
6,181,126
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top