Case macro help

Tonyk1051

Board Regular
Joined
Feb 1, 2021
Messages
132
Office Version
  1. 2019
Platform
  1. Windows
Hi,

Can some one help create a Macro for the rules below for the worksheet in the link? would be much appreciated, thanks (i tried doing one myself using a "case" macro it was an utter failure...

if column G is denied by manufacture, denied by defect, denied by product type or sku or denied dis. time frame has open box in column W (Defect Cat)
then put in column H REEVALUATE - TO STOCK OR USED

if column G is denied by manufacture, denied by defect, denied by product type or sku or denied dis. time frame has Defective / unspecified in column W (Defect Cat)
then put in column H, MFR

if column W has keyword damaged and column O is less than $300 then put in column H, TL UNLESS if column J is tested confirmed defective or tested confirmed damaged put in column H, liq.com
if column T is 3years old from todays date then put in column H, TL
if column F is Viewsonic, LG or NEC and column W is Defective/ unspecified then in column H put pic of defect required
if column N has keyword television or monitors and column W is damaged then put in column H TL
if column N has keyword unlocked cell phones and column X is not all upper case text then put in column H, TT

test.xlsm heres the link to the file
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi,

Can some one help create a Macro for the rules below for the worksheet in the link? would be much appreciated, thanks (i tried doing one myself using a "case" macro it was an utter failure...

if column G is denied by manufacture, denied by defect, denied by product type or sku or denied dis. time frame has open box in column W (Defect Cat)
then put in column H REEVALUATE - TO STOCK OR USED

if column G is denied by manufacture, denied by defect, denied by product type or sku or denied dis. time frame has Defective / unspecified in column W (Defect Cat)
then put in column H, MFR

if column W has keyword damaged and column O is less than $300 then put in column H, TL UNLESS if column J is tested confirmed defective or tested confirmed damaged put in column H, liq.com
if column T is 3years old from todays date then put in column H, TL
if column F is Viewsonic, LG or NEC and column W is Defective/ unspecified then in column H put pic of defect required
if column N has keyword television or monitors and column W is damaged then put in column H TL
if column N has keyword unlocked cell phones and column X is not all upper case text then put in column H, TT

test.xlsm heres the link to the file
I never click on links.

How do you plan to run this script? By pressing a button or what?
 
Upvote 0
Don't have dropbox, can you upload somewhere else for example here <--- and then provide the link?
 
Upvote 0
If your trying to learn case statements:

Here is a sheet change event script using Case:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  10/24/2021  8:59:04 PM  EDT
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub

    If Target.Column = 1 Then
        
        Select Case Target.Value
            Case "Alpha", "Bravo", "Charlie"
                Target.Offset(, 1).Value = "Yes"
    
            Case "Delta", "Echo", "Foxtrot"
                Target.Offset(, 1).Value = "No"
            
        End Select

End If
End Sub
 
Upvote 0
Ok here is a quick summary of the file for those that don't like to download from links:

test.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAK
1Item IDKit FlagSourceVendorVendor LiasonManufacturerRTV CategoryDate RTV CategoryUser RTV CategoryShelfPrior CategoryProduct groupBooknetWarehouseHas LithiumOpen BoxDFIDate RcvdCustomer Purchase DateRMA DateDefect DescSerial NoItem CodeCust FlagCatalog NoBuyerBrandDescriptionLongn Catalog NoPoIs usedMulti Vendor FlagLast VendorReturn Reason 1
2INGRAM MICROViewSonicDENIED DIST. TIMEFRAMEMULTIMEDIA-See All Projectors864.3110/5/21Oct 1, 202110/3/21Open BoxOPEN BOX
3LG ELECTRONICS USA, INCnaricsLGPICTURE OF DEFECT DONEPICTURE OF DEFECT REQUIREDCOMPUTERS-Computer Monitors945.99NOSEE NOTES6/15/21Feb 2, 20212/14/21Damagedbox suffered damage/holes....unit will not turn on
4TECH DATA CORP.NECDENIED DIST. TIMEFRAMECOMPUTERS-Computer Monitors389.5810/1/21Aug 11, 20218/16/21Defective / unspecifieddoa
5SAMSUNG ELECTRONICS AMERICASamsungDENIED BY MANUFACTURECOMPUTERS-Computer Monitors237.599/3/21Defective / unspecifiedper case # 59136369 screen flickers and does not show the display
6TECH DATA/SONY PRODUCTSSonyDENIED DEFECTHEADPHONES-Headphones1210/15/21Open BoxOPEN BOX
7EPSON AMERICA, INCnaricsEpsonDENIED PRODUCT TYPE OR SKUPRINTERS-Inkjet Printers Accessories8.49SEE NOTENO10/7/21Open BoxBOX IS BROKEN
8TECH DATA CORP.NECDENIED DIST. TIMEFRAMECOMPUTERS-Computer Monitors389.5810/1/21Aug 11, 20218/16/21Defective / unspecifieddoa
9JEG & SONS INC.SamsungDENIED DIST. TIMEFRAMEMOBILE-Unlocked Cell Phones3451/25/21Nov 20, 20191/7/21Defective / unspecifiedPHONE SCREEN FAILED
10BBQ TRADING LLCtonykOnePlusTESTED CONFIRMED DEFECTIVETESTING TEAMMOBILE-Unlocked Cell Phones325NONO2/17/21Nov 27, 20201/24/21Defective / unspecifiedThe screen has stopped responding
11DIGITAL DATA DISTRIBUTORSllavnerLGMANUFACTURETELEVISIONS-Televisions1,896.25NO10/4/21Sep 9, 20219/14/21DamagedCRACKED SCREEN
12TECH DATA CORP.AppleDENIED DIST. TIMEFRAMECOMPUTER-Computer Monitor Adapters59.3910/11/21Aug 24, 202110/6/21Open BoxOPEN BOX
13TECH DATA CORP.NECDENIED DIST. TIMEFRAMEMULTIMEDIA-Commercial Monitors1,00010/7/21Aug 10, 2021Defective / unspecifiedDOESNT WORK ,
14D & H DISTRIBUTING CO.tonykDatacolorMANUFACTUREDENIED DIST. TIMEFRAMECOMPUTER MONITORS-Calibration249.33SEE NOTENO1/19/21Oct 12, 202011/1/20Defective / unspecifiedTHE SOFTWARE NEEDED TO OPERATE THIS DEVICE DOESNT WO HIS BE EXCHANGED WITH?
15D & H DISTRIBUTING CO.tonykMSIMANUFACTUREDENIED DIST. TIMEFRAMECOMPUTERS-Portable Monitors191SEE NOTENO9/10/21Aug 2, 20219/1/21Defective / unspecifiedThis monitor will not recognize the HDMI input.
16ROLAND CORPORATION U.S.BossDENIED DEFECTGUITARS-Effects Pedals73.2310/13/18Open BoxOPEN BOX
17TECH DATA CORP.tonykNECPICTURE OF DEFECT DONEPICTURE OF DEFECT REQUIREDMULTIMEDIA-Commercial Monitors895YESNO3/21/18Mar 6, 20183/9/18Damagedwhite line in middle of screen, no box damage
18LINECO INC.LinecoDENIED BY MANUFACTUREARCHIVAL STORAGE-Museum & Preservation Boxes14.49/19/21DamagedThe box both outer and inner came damaged.
19EPSON AMERICA, INCEpsonDENIED DEFECTPRINTERS-Large Format Printers1,7567/12/21DamagedBox is damaged.
20TECH DATA CORP.HPDENIED DIST. TIMEFRAMECOMPUTER-Notebooks2,022.8210/5/21Mar 22, 202110/5/21DamagedDAMAGED IN TRANSIT
21
22
23
24
25
On a Category


And here is a quick summary of the OP intentions:

if column F is 'ViewSonic', 'LG' or 'NEC' and column W is 'Defective / unspecified' then put in column H 'PICTURE OF DEFECT REQUIRED'

if column G is 'DENIED BY MANUFACTURE', 'DENIED DEFECT', 'DENIED PRODUCT TYPE OR SKU' or 'DENIED DIST. TIMEFRAME' has 'Open Box' in column W
then put in column H 'REEVALUATE - TO STOCK OR USED'

if column G is 'DENIED BY MANUFACTURE', 'DENIED DEFECT', 'DENIED PRODUCT TYPE OR SKU' or 'DENIED DIST. TIMEFRAME' has 'Defective / unspecified' in column W
then put in column H 'MFR'

if column N is 'MOBILE-Unlocked Cell Phones' and column X is not all upper case text then put in column H 'TT'
if column N is ;TELEVISIONS-Televisions' or 'COMPUTERS-Computer Monitors' or 'COMPUTER-Computer Monitor Adapters' or 'MULTIMEDIA-Commercial Monitors' or 'COMPUTER MONITORS-Calibration' Or
'COMPUTERS-Portable Monitors' and column W is damaged then put in column H 'TL'

if column T is 3years old from todays date then put in column H 'TL'

if column W is 'Damaged' and column O is less than $300 then put in column H, TL, UNLESS ...
' ---> This hasn't been seen ---> if column J is tested confirmed defective or tested confirmed damaged then put in column H, liq.com

@Tonyk1051 please correct/add to anything that I may have incorrect. I have posted this in hopes of getting you more responses to your OP.
 
Upvote 0
Ok here is a quick summary of the file for those that don't like to download from links:

test.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAK
1Item IDKit FlagSourceVendorVendor LiasonManufacturerRTV CategoryDate RTV CategoryUser RTV CategoryShelfPrior CategoryProduct groupBooknetWarehouseHas LithiumOpen BoxDFIDate RcvdCustomer Purchase DateRMA DateDefect DescSerial NoItem CodeCust FlagCatalog NoBuyerBrandDescriptionLongn Catalog NoPoIs usedMulti Vendor FlagLast VendorReturn Reason 1
2INGRAM MICROViewSonicDENIED DIST. TIMEFRAMEMULTIMEDIA-See All Projectors864.3110/5/21Oct 1, 202110/3/21Open BoxOPEN BOX
3LG ELECTRONICS USA, INCnaricsLGPICTURE OF DEFECT DONEPICTURE OF DEFECT REQUIREDCOMPUTERS-Computer Monitors945.99NOSEE NOTES6/15/21Feb 2, 20212/14/21Damagedbox suffered damage/holes....unit will not turn on
4TECH DATA CORP.NECDENIED DIST. TIMEFRAMECOMPUTERS-Computer Monitors389.5810/1/21Aug 11, 20218/16/21Defective / unspecifieddoa
5SAMSUNG ELECTRONICS AMERICASamsungDENIED BY MANUFACTURECOMPUTERS-Computer Monitors237.599/3/21Defective / unspecifiedper case # 59136369 screen flickers and does not show the display
6TECH DATA/SONY PRODUCTSSonyDENIED DEFECTHEADPHONES-Headphones1210/15/21Open BoxOPEN BOX
7EPSON AMERICA, INCnaricsEpsonDENIED PRODUCT TYPE OR SKUPRINTERS-Inkjet Printers Accessories8.49SEE NOTENO10/7/21Open BoxBOX IS BROKEN
8TECH DATA CORP.NECDENIED DIST. TIMEFRAMECOMPUTERS-Computer Monitors389.5810/1/21Aug 11, 20218/16/21Defective / unspecifieddoa
9JEG & SONS INC.SamsungDENIED DIST. TIMEFRAMEMOBILE-Unlocked Cell Phones3451/25/21Nov 20, 20191/7/21Defective / unspecifiedPHONE SCREEN FAILED
10BBQ TRADING LLCtonykOnePlusTESTED CONFIRMED DEFECTIVETESTING TEAMMOBILE-Unlocked Cell Phones325NONO2/17/21Nov 27, 20201/24/21Defective / unspecifiedThe screen has stopped responding
11DIGITAL DATA DISTRIBUTORSllavnerLGMANUFACTURETELEVISIONS-Televisions1,896.25NO10/4/21Sep 9, 20219/14/21DamagedCRACKED SCREEN
12TECH DATA CORP.AppleDENIED DIST. TIMEFRAMECOMPUTER-Computer Monitor Adapters59.3910/11/21Aug 24, 202110/6/21Open BoxOPEN BOX
13TECH DATA CORP.NECDENIED DIST. TIMEFRAMEMULTIMEDIA-Commercial Monitors1,00010/7/21Aug 10, 2021Defective / unspecifiedDOESNT WORK ,
14D & H DISTRIBUTING CO.tonykDatacolorMANUFACTUREDENIED DIST. TIMEFRAMECOMPUTER MONITORS-Calibration249.33SEE NOTENO1/19/21Oct 12, 202011/1/20Defective / unspecifiedTHE SOFTWARE NEEDED TO OPERATE THIS DEVICE DOESNT WO HIS BE EXCHANGED WITH?
15D & H DISTRIBUTING CO.tonykMSIMANUFACTUREDENIED DIST. TIMEFRAMECOMPUTERS-Portable Monitors191SEE NOTENO9/10/21Aug 2, 20219/1/21Defective / unspecifiedThis monitor will not recognize the HDMI input.
16ROLAND CORPORATION U.S.BossDENIED DEFECTGUITARS-Effects Pedals73.2310/13/18Open BoxOPEN BOX
17TECH DATA CORP.tonykNECPICTURE OF DEFECT DONEPICTURE OF DEFECT REQUIREDMULTIMEDIA-Commercial Monitors895YESNO3/21/18Mar 6, 20183/9/18Damagedwhite line in middle of screen, no box damage
18LINECO INC.LinecoDENIED BY MANUFACTUREARCHIVAL STORAGE-Museum & Preservation Boxes14.49/19/21DamagedThe box both outer and inner came damaged.
19EPSON AMERICA, INCEpsonDENIED DEFECTPRINTERS-Large Format Printers1,7567/12/21DamagedBox is damaged.
20TECH DATA CORP.HPDENIED DIST. TIMEFRAMECOMPUTER-Notebooks2,022.8210/5/21Mar 22, 202110/5/21DamagedDAMAGED IN TRANSIT
21
22
23
24
25
On a Category


And here is a quick summary of the OP intentions:

if column F is 'ViewSonic', 'LG' or 'NEC' and column W is 'Defective / unspecified' then put in column H 'PICTURE OF DEFECT REQUIRED'

if column G is 'DENIED BY MANUFACTURE', 'DENIED DEFECT', 'DENIED PRODUCT TYPE OR SKU' or 'DENIED DIST. TIMEFRAME' has 'Open Box' in column W
then put in column H 'REEVALUATE - TO STOCK OR USED'

if column G is 'DENIED BY MANUFACTURE', 'DENIED DEFECT', 'DENIED PRODUCT TYPE OR SKU' or 'DENIED DIST. TIMEFRAME' has 'Defective / unspecified' in column W
then put in column H 'MFR'

if column N is 'MOBILE-Unlocked Cell Phones' and column X is not all upper case text then put in column H 'TT'
if column N is ;TELEVISIONS-Televisions' or 'COMPUTERS-Computer Monitors' or 'COMPUTER-Computer Monitor Adapters' or 'MULTIMEDIA-Commercial Monitors' or 'COMPUTER MONITORS-Calibration' Or
'COMPUTERS-Portable Monitors' and column W is damaged then put in column H 'TL'

if column T is 3years old from todays date then put in column H 'TL'

if column W is 'Damaged' and column O is less than $300 then put in column H, TL, UNLESS ...
' ---> This hasn't been seen ---> if column J is tested confirmed defective or tested confirmed damaged then put in column H, liq.com

@Tonyk1051 please correct/add to anything that I may have incorrect. I have posted this in hopes of getting you more responses to your OP.
sorry for the delay, all the rules you have are correct
 
Upvote 0
If your trying to learn case statements:

Here is a sheet change event script using Case:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  10/24/2021  8:59:04 PM  EDT
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub

    If Target.Column = 1 Then
       
        Select Case Target.Value
            Case "Alpha", "Bravo", "Charlie"
                Target.Offset(, 1).Value = "Yes"
   
            Case "Delta", "Echo", "Foxtrot"
                Target.Offset(, 1).Value = "No"
           
        End Select

End If
End Sub
this actually helped me out alot i managed to create a macro for the denied rules and it works perfect but im stuck for the rule
if column W is 'Damaged' and column O is less than $300 then put in column H, TL, UNLESS if column J is tested confirmed damaged then put in column H, liq.com below is the code i made and it kind of works, it will put anything that is damaged under 300 to TL but its supposed to change to liq.com if it also has "tested confirmed damaged" please see below and let me know what i need to change or if theres a better way to go about this

Code:
Sub ljbnj()

Dim cel As Range, Rng As Range, Defect As String

Worksheets("On a Category").Activate

Range("W2").Select

Set Rng = Range(Selection, Selection.End(xlDown))

For Each cel In Rng

Defect = cel.Text

Select Case Defect

Case "Damaged"

If cel.Offset(, 0) = "Damaged" And cel.Offset(, -8) <= 300 Then

cel.Offset(, -15) = "TL"

ElseIf cel.Offset(, -16) = "TESTED CONFIRMED DAMAGED" Then

cel.Offset(, -15) = "liq.com"

End If

'etcetera

End Select

cel.Offset(, -15).Interior.Color = vbGreen 'So you can see what already is done

Next cel



End Sub
 
Upvote 0
Try the following:

VBA Code:
Sub newTest()
'
'   Turn Settings off
      Application.ScreenUpdating = False                                    ' Turn Screen Updating off
         Application.Calculation = xlCalculationManual                      ' Turn AutoCalculation off
        Application.EnableEvents = False                                    ' Turn EnableEvents off
'
    Dim FirstRowOfData  As Long
    Dim LastRowInSheet  As Long
    Dim cel             As Range, Rng As Range
    Dim ThisCell        As String
    Dim wsDestination   As Worksheet
'
    FirstRowOfData = 2                                                                                                  ' <--- Set this value
    Set wsDestination = Sheets("Sheet17")                                                                                   ' <--- Set this to correct sheet
'
    LastRowInSheet = wsDestination.Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row    ' Find last used Row in sheet
'
'----------------------------------------------------------------------------------------------------------------------
'
    Set Rng = Range("F" & FirstRowOfData & ":F" & LastRowInSheet)                                                       ' F column
'
    For Each cel In Rng
        ThisCell = cel.Text
'
        Select Case ThisCell
            Case "ViewSonic", "LG", "NEC"
                If cel.Offset(0, 17) = "Defective / unspecified" Then cel.Offset(0, 2) = "PICTURE OF DEFECT REQUIRED"
        End Select
    Next
'
'----------------------------------------------------------------------------------------------------------------------
'
    Set Rng = Range("G" & FirstRowOfData & ":G" & LastRowInSheet)                                                       ' G column
'
    For Each cel In Rng
        ThisCell = cel.Text
'
        Select Case ThisCell
            Case "DENIED BY MANUFACTURE", "DENIED DEFECT", "DENIED PRODUCT TYPE OR SKU", "DENIED DIST. TIMEFRAME"
                If cel.Offset(0, 16) = "Open Box" Then cel.Offset(0, 1) = "REEVALUATE - TO STOCK OR USED"
                If cel.Offset(0, 16) = "Defective / unspecified" Then cel.Offset(0, 1) = "MFR"
        End Select
    Next
'
'----------------------------------------------------------------------------------------------------------------------
'
    Set Rng = Range("N" & FirstRowOfData & ":N" & LastRowInSheet)                                                       ' N column
'
    For Each cel In Rng
        ThisCell = cel.Text
'
        Select Case ThisCell
            Case "MOBILE-Unlocked Cell Phones"
                If cel.Offset(0, 10) <> UCase(cel.Offset(0, 10)) Then cel.Offset(0, -6) = "TT"                          ' If column X not all caps then ...
            Case "TELEVISIONS-Televisions", "COMPUTERS-Computer Monitors", "COMPUTER-Computer Monitor Adapters", "MULTIMEDIA-Commercial Monitors", "COMPUTER MONITORS-Calibration", "COMPUTERS-Portable Monitors"
                If cel.Offset(0, 9) = "Damaged" Then cel.Offset(0, -6) = "TL"
        End Select
    Next
'
'----------------------------------------------------------------------------------------------------------------------
'
    Set Rng = Range("T" & FirstRowOfData & ":T" & LastRowInSheet)                                                       ' T column
'
    For Each cel In Rng
        If DateAdd("yyyy", 3, cel) < Date Then cel.Offset(0, -12) = "TL"
    Next
'
'----------------------------------------------------------------------------------------------------------------------
'
    Set Rng = Range("W" & FirstRowOfData & ":W" & LastRowInSheet)                                                       ' W column
'
    For Each cel In Rng
        ThisCell = cel.Text
'
        Select Case ThisCell
            Case "Damaged"
                If cel.Offset(0, -8) < 300 Then
                    If cel.Offset(0, -13) = "tested confirmed defective" Or cel.Offset(0, -13) = "tested confirmed damaged" Then
                        cel.Offset(0, -15) = "liq.com"
                    Else
                        cel.Offset(0, -15) = "TL"
                    End If
                End If
        End Select
    Next
'
'----------------------------------------------------------------------------------------------------------------------
'
'   Turn Settings back on
    Application.EnableEvents = True                                                             ' Turn EnableEvents back on
    Application.Calculation = xlCalculationAutomatic                                            ' Turn AutoCalculation back on
    Application.ScreenUpdating = True                                                           ' Turn Screen Updating back on
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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