Transfer Items on a List by Quantity

nniedzielski

Well-known Member
Joined
Jan 8, 2016
Messages
598
Office Version
  1. 2019
Platform
  1. Windows
I am currently running a Macro that takes items from a List:
1584712955879.png

And I run this code to scroll through the Master Inventory worksheet and pulls anything that is on this list onto the Fruits Tab, then removes some un-needed columns, and does some formatting.

VBA Code:
With Worksheets("Lists")
        mtArray = .Range("C2", .Range("C" & Rows.Count).End(xlUp))
    End With
    With Sheets("Master Inventory")
        .Range("A1:S1").AutoFilter field:=1, Criteria1:=Application.Transpose(mtArray), Operator:=xlFilterValues
        .AutoFilter.Range.Copy Sheets("Fruits").Range("A1")
        .AutoFilter.Range.Offset(1).EntireRow.Delete
        .Range("A1:S1").AutoFilter
    End With
    With Sheets("Fruits").Range("D:S")
        .EntireColumn.Delete
    End With
    With Sheets("Fruits").Range("A1:C1")
        .Font.Bold = True
    End With
    With Sheets("Fruits").UsedRange.Borders
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    Sheets("Fruits").UsedRange.EntireColumn.AutoFit

What I need to add to this functionality is the ability to set a Max number of Fruits:
1584713171526.png

In this i would only want the macro to grab the first 12 rows of data with Lemons in it, first 5 with Oranges and so on and so forth and move them to the fruits tab.

How can i add this in?

thank you as always for any help, Stay safe
 
Glad to hear that & thanks for the feedback
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
For whatever reason, my work laptop will not allow me to do Run dictionary.

You tried adding the reference:
Go to References ->
Select “Microsoft Scripting Runtime”

I'm going to use Peter's formula, but using the autofilter, try this option:

VBA Code:
Sub test2()
  Dim lr As Long, sh As Worksheet, m
  
  Set sh = Sheets("Master Inventory")
  If sh.AutoFilterMode Then sh.AutoFilterMode = False
  lr = sh.Range("A" & Rows.Count).End(3).Row
  sh.Range("Z2:Z" & lr).Formula = "=COUNTIF(A$2:A2,A2)<=VLOOKUP(A2,Lists!C:D,2,0)"
    
  sh.Range("A1:Z" & lr).AutoFilter 26, "TRUE"
  sh.AutoFilter.Range.Range("A:C").Copy Sheets("Fruits").Range("A1")
  With Sheets("Fruits")
    .UsedRange.Borders.LineStyle = xlContinuous
    .UsedRange.EntireColumn.AutoFit
  End With
  sh.AutoFilter.Range.Offset(1).EntireRow.Delete
  sh.ShowAllData
  sh.Range("Z:Z").ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,811
Messages
6,127,017
Members
449,351
Latest member
Sylvine

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