Filtering different brands of items into new sheet

alvin97

New Member
Joined
Sep 26, 2024
Messages
23
Office Version
  1. 365
Platform
  1. Windows
I needs help on with filter different brand of item, as current VBA code was all using range cell to filter into different column. This make a lot of code needed to amend when there is a new product. Is there a way to filter each brand with unique SKU like (BrandA, BrandB, BrandC)? Thanks

Before
1727343546089.png

After
1727343617999.png


VBA Code:
Sub Report()

Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Main"

Dim ResultCell As Range
Dim Sheet As Worksheet

Set Sheet = ActiveWorkbook.Sheets.Add(After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count))
Sheet.Name = "Report"

Sheets("Main").Range("$A$4:$A$21").Copy
Sheets("Report").Activate
Range("A4").Select
ActiveSheet.Paste

Sheets("Main").Range("$A$22:$A$35").Copy
Sheets("Report").Activate
Range("D4").Select
ActiveSheet.Paste

Sheets("Main").Range("$A$36:$A$45").Copy
Sheets("Report").Activate
Range("G4").Select
ActiveSheet.Paste


    Dim LookupValueCell As Range
    Dim LookupVector As Range
    Dim ResultVector As Range

    
    Set ResultCell = Sheets("Report").Range("$B$4:$B$21")
    Set LookupValueCell = Sheets("Report").Range("$A$4:$A$400")
    Set LookupVector = Sheets("Main").Range("$A$4:$A$400")
    Set ResultVector = Sheets("Main").Range("$B$4:$B$23")

ResultCell = WorksheetFunction.Lookup(LookupValueCell, LookupVector, ResultVector)

    Dim LookupValueCell1 As Range
    Dim LookupVector1 As Range
    Dim ResultVector1 As Range
    Dim ResultCell1 As Range
    
    
    Set ResultCell1 = Sheets("Report").Range("$E$4:$E$17")
    Set LookupValueCell1 = Sheets("Report").Range("$D$4:$D$400")
    Set LookupVector1 = Sheets("Main").Range("$A$4:$A$400")
    Set ResultVector1 = Sheets("Main").Range("$B$4:$B$372")

ResultCell1 = WorksheetFunction.Lookup(LookupValueCell1, LookupVector1, ResultVector1)

    Dim LookupValueCell2 As Range
    Dim LookupVector2 As Range
    Dim ResultVector2 As Range
    Dim ResultCell2 As Range
    
    
    Set ResultCell2 = Sheets("Report").Range("$H$4:$H$13")
    Set LookupValueCell2 = Sheets("Report").Range("$G$4:$H$400")
    Set LookupVector2 = Sheets("Main").Range("$A$4:$A$400")
    Set ResultVector2 = Sheets("Main").Range("$B$4:$B$372")

ResultCell2 = WorksheetFunction.Lookup(LookupValueCell2, LookupVector2, ResultVector2)
 
DateString = Format(Now, "DDMMMYYYY")
[B1].Value = DateString
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Column E+G+I=K (this was fomulate in another system)
Column F+H+J=L (this was fomulate in another system)

Inventory_Products_Stock_Level_Report_testing.xlsm
ABCDEFGHIJKLM
1Location1Location1Location 2Location 2Location3Location3Grand TotalGrand Total
2SKUUnit extract from SKUProductUnitAvailableAllocatedAvailableAllocatedAvailableAllocatedAvailableAllocatedTotal
3HTDKG107Model1 - SeriesA / HTDKG107$E$2$F$2$G$2$H$2$I$2$J$2914.00$L$39.14
4HTDKG108Model1 - SeriesB / HTDKG108$E$3$F$3$G$3$H$3$I$3$J$3900.00$L$49
5HTDKG109Model1 - SeriesC / HTDKG109$E$4$F$4$G$4$H$4$I$4$J$41,170.00$L$511.7
6HTDKG110Model1 - SeriesD / HTDKG110$E$5$F$5$G$5$H$5$I$5$J$5490.00$L$64.9
7HTDKG111Model1 - SeriesE / HTDKG111$E$6$F$6$G$6$H$6$I$6$J$61,500.00$L$715
8HTK001Model2 - SeriesF / HTK001$E$7$F$7$G$7$H$7$I$7$J$72,318.00$L$823.18
9HTK002Model2 - SeriesG / HTK002$E$8$F$8$G$8$H$8$I$8$J$81,518.00$L$915.18
10HTK003Model2 - SeriesH / HTK003$E$9$F$9$G$9$H$9$I$9$J$92,866.00$L$1028.66
11HTK005Model2 - SeriesI / HTK005$E$10$F$10$G$10$H$10$I$10$J$10240.00$L$112.4
12HTK006Model2 - SeriesJ / HTK006$E$11$F$11$G$11$H$11$I$11$J$112,318.00$L$1223.18
13HTK014Model2 - SeriesK / HTK014$E$12$F$12$G$12$H$12$I$12$J$12546.00$L$135.46
14HTK016Model2 - SeriesL / HTK016$E$13$F$13$G$13$H$13$I$13$J$131,505.00$L$1415.05
16HTDG01Model3 / HTDG01$E$15$F$15$G$15$H$15$I$15$J$152,198.00$L$1621.98
18HTDG02Model3 / HTDG02$E$17$F$17$G$17$H$17$I$17$J$172,214.00$L$1822.14
20HTDG03Model3 / HTDG03$E$19$F$19$G$19$H$19$I$19$J$191,850.00$L$2018.5
22HTDG04Model3 / HTDG04$E$21$F$21$G$21$H$21$I$21$J$211,384.00$L$2213.84
24HTDG05Model3 / HTDG05$E$23$F$23$G$23$H$23$I$23$J$23740.00$L$247.4
Main
Cell Formulas
RangeFormula
M3:M14,M16,M18,M20,M22,M24M3=$K3/100
 
Upvote 0
Column E+G+I=K (this was fomulate in another system)
Column F+H+J=L (this was fomulate in another system)

Inventory_Products_Stock_Level_Report_testing.xlsm
ABCDEFGHIJKLM
1Location1Location1Location 2Location 2Location3Location3Grand TotalGrand Total
2SKUUnit extract from SKUProductUnitAvailableAllocatedAvailableAllocatedAvailableAllocatedAvailableAllocatedTotal
3HTDKG107Model1 - SeriesA / HTDKG107$E$2$F$2$G$2$H$2$I$2$J$2914.00$L$39.14
4HTDKG108Model1 - SeriesB / HTDKG108$E$3$F$3$G$3$H$3$I$3$J$3900.00$L$49
5HTDKG109Model1 - SeriesC / HTDKG109$E$4$F$4$G$4$H$4$I$4$J$41,170.00$L$511.7
6HTDKG110Model1 - SeriesD / HTDKG110$E$5$F$5$G$5$H$5$I$5$J$5490.00$L$64.9
7HTDKG111Model1 - SeriesE / HTDKG111$E$6$F$6$G$6$H$6$I$6$J$61,500.00$L$715
8HTK001Model2 - SeriesF / HTK001$E$7$F$7$G$7$H$7$I$7$J$72,318.00$L$823.18
9HTK002Model2 - SeriesG / HTK002$E$8$F$8$G$8$H$8$I$8$J$81,518.00$L$915.18
10HTK003Model2 - SeriesH / HTK003$E$9$F$9$G$9$H$9$I$9$J$92,866.00$L$1028.66
11HTK005Model2 - SeriesI / HTK005$E$10$F$10$G$10$H$10$I$10$J$10240.00$L$112.4
12HTK006Model2 - SeriesJ / HTK006$E$11$F$11$G$11$H$11$I$11$J$112,318.00$L$1223.18
13HTK014Model2 - SeriesK / HTK014$E$12$F$12$G$12$H$12$I$12$J$12546.00$L$135.46
14HTK016Model2 - SeriesL / HTK016$E$13$F$13$G$13$H$13$I$13$J$131,505.00$L$1415.05
16HTDG01Model3 / HTDG01$E$15$F$15$G$15$H$15$I$15$J$152,198.00$L$1621.98
18HTDG02Model3 / HTDG02$E$17$F$17$G$17$H$17$I$17$J$172,214.00$L$1822.14
20HTDG03Model3 / HTDG03$E$19$F$19$G$19$H$19$I$19$J$191,850.00$L$2018.5
22HTDG04Model3 / HTDG04$E$21$F$21$G$21$H$21$I$21$J$211,384.00$L$2213.84
24HTDG05Model3 / HTDG05$E$23$F$23$G$23$H$23$I$23$J$23740.00$L$247.4
Main
Cell Formulas
RangeFormula
M3:M14,M16,M18,M20,M22,M24M3=$K3/100
So do you want in the report, for example from row 3,
HTDKG107
or
Model1 - SeriesA / HTDKG107?
 
Upvote 0
So do you want in the report, for example from row 3,
HTDKG107
or
Model1 - SeriesA / HTDKG107?
For my Report, I just need my sku (HTDKG107 A3) and my total (M3) and arrange in each brand in each Column.

For example this below (this is what i wanted as my final result)
A3:M3
A4:M4
and continue while arrange via HTDKG, HTK and HTDG
27-Sep-24
HTDKG1079.14HTK00123.18HTDG0121.98
HTDKG1089HTK00215.18HTDG0222.14
HTDKG10911.7HTK00328.66HTDG0318.5
HTDKG1104.9HTK0052.4HTDG0413.84
HTDKG11115HTK00623.18HTDG057.4
HTK0145.46HTDG0623.38
HTK01615.05HTDG0719.8
HTDG0817.52
HTDG0914.8
HTDG109.33
HTDG117.33
HTDG1217.2
 
Upvote 0
You have created what in wanted in thread #13 but that code only filter to the word "Brand". But I need to filter based on this (HTDKG, HTK and HTDG).
Thank you
 
Upvote 0
You have created what in wanted in thread #13 but that code only filter to the word "Brand". But I need to filter based on this (HTDKG, HTK and HTDG).
Thank you
Try removing the first row. It is rare for data sets to more than one header row.
 
Upvote 0
Try removing the first row. It is rare for data sets to more than one header row.
I have tried delete the first row, but there is 1004 error on this code "WsReport.Range("A4").Offset(0, (i - 1) * 3).Formula2 = strFormula = False". After i change my HTDKG, HTK and HTDG to BrandA, BrandB, and BrandC, the report came working correctly.
So is there a way to filter from "Brand" change to my sku code?
 
Last edited:
Upvote 0
Use your data with the first row deleted and no blank rows.

Use this code. I used the data as in post 24.

VBA Code:
Public Sub subFilterBrands()
Dim arrBrands() As Variant
Dim i As Integer
Dim rngData As Range
Dim WsReport As Worksheet
Dim WsMain As Worksheet
Dim Wb As Workbook
Dim Q As String
Dim strFormula As String

  ActiveWorkbook.Save
  
  Set Wb = ActiveWorkbook
  
  Q = Chr(34)
    
  Set WsMain = Wb.Sheets("Main")
  
  WsMain.Activate
   
  strFormula = "=SUBSTITUTE($A2,TEXTJOIN(" & Q & Q & ",TRUE,IFERROR((MID($A2,ROW(INDIRECT(" & Q & "1:" & Q & "&LEN($A2))),1)*1)," & Q & Q & "))," & Q & Q & ",1)"
  
  WsMain.Range("B1").EntireColumn.Insert
  
  With WsMain.Range("A1").CurrentRegion.Columns(1)
  
    With .Offset(1, 1).Resize(.Rows.Count, 1)
      .Cells(1).Offset(-1, 0).Value = "Brand"
      .Formula2 = strFormula
      .Value = .Value
    End With
  
  End With
  
  Application.DisplayAlerts = False
  On Error Resume Next
  Wb.Worksheets("Report").Delete
  On Error GoTo 0
  Application.DisplayAlerts = True
  
  Set WsReport = ActiveWorkbook.Sheets.Add(After:=Wb.Sheets(Wb.Sheets.Count))

  WsReport.Name = "Report"
  
  With WsMain.Range("A1").CurrentRegion
  
    With .Offset(1, 0).Resize(.Rows.Count, .Columns.Count)
       
      arrBrands = Evaluate("SORT(UNIQUE(" & WsMain.Name & "!" & .Columns(2).Address & "),1)")
    
      For i = LBound(arrBrands) To UBound(arrBrands) - 1
                  
        strFormula = "=CHOOSECOLS(FILTER(" & WsMain.Name & "!" & .Address & "," & WsMain.Name & "!" & .Columns(2).Address & "=" & Q & arrBrands(i, 1) & Q & ",""""),2,14)"
  
        WsReport.Range("A4").Offset(0, (i - 1) * 3).Formula2 = strFormula
    
      Next i
  
    End With
    
  End With
    
  With WsReport
    .UsedRange.Value = WsReport.UsedRange.Value
    .Cells.EntireColumn.AutoFit
  End With
    
  WsMain.Range("B1").EntireColumn.Delete
  
  MsgBox "Reports Compiled.", vbOKOnly, "Confirmation"
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
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