HOW TO ACCOMPLISH a vba IF/THEN FILTER? example is attached

ChrisOK

Well-known Member
Joined
Mar 26, 2003
Messages
601
My current code is pulling too much; need to incorporate this filtering step ASAP but not sure how to accomplish?:
Attached small sample for your viewing to help expedite understanding>: https://app.box.com/s/2h3dhbnsmgcw2rq0soa1

THERE ARE 2 PHASES:

1st Phase, DETERMINE WHAT CODE SHOULD BE USED WHEN WORKING THIS PART #
================================================================
Using the Example:
Target Cell: "J3" of PARTS sheet is PN# 1461M87G24
1- Look for "J3's" MATCH within the TECHORDER sheet Col B
...............................................................
....If MATCH is located:
.........proceed with the 2nd phase using the NON-COLORED cells
................................................................
....If NO MATCH is located, MsgBox: "no match found"


2nd, LOCATE ROWS THAT MEET THE CONDITIONS and COPY a few pieces of Data from that row of TECH ORDER to PARTS sheet
=====================================================================================================
*- Most important Rule/Condition: ONLY USE CELLS that have NOT BEEN colorized
1- Look through Col H for the code identified in Phase 1 (within only NON-COLORED cells)
2- Look through Col H for empty/blank cells (for only the NON-COLORED cells)

IF either 1 or 2 conditions are met/TRUE
THEN, RUN the code I already have (below) to copy adjacent data

================================================================================
I found a line of code that looks at a cell's color, perhaps it can be used somehow
Range("H8:H").Interior.ColorIndex = 0
================================================================================

Here's the code that will follow (and perform the final step of copying):
Code:
Sheets("TECHORDER").Select

Dim x As Range, pnrng As Range, nr As Long
Application.ScreenUpdating = False
With Sheets("TECHORDER")
  For Each x In .Range("B7", .Range("B" & Rows.Count).End(xlUp))
    Set pnrng = Sheets("PARTS").Columns(16).Find(x.Value, lookat:=xlWhole)
    
'COPY THE ADJACENT DATA FOUND on "TechOrder" to the base of the PARTS sheet
'....."TECHORDER" to "PARTS" COLUMNS are: AtoR, BtoP, FtoO and GtoE

    If pnrng Is Nothing Then
      nr = Sheets("PARTS").Range("P" & Rows.Count).End(xlUp).Offset(1).Row
      With Sheets("PARTS").Range("P" & nr)
        .Value = x.Value
        .Font.FontStyle = "Bold"
        .Font.Color = 255
      End With
      
      With Sheets("PARTS").Range("O" & nr)
        .Value = x.Offset(, 4).Value
        .Font.FontStyle = "Bold"
        .Font.Color = 255
      End With
      
      With Sheets("PARTS").Range("E" & nr)
        .Value = x.Offset(, 5).Value
        .Font.FontStyle = "Bold"
        .Font.Color = 255
      End With
      

' Prob w/ Fig Ref converting into dates and odd numbers like 41319. This is Format>Cells>Text prior to pasting data into it.
' but is still not working quite right - figure out later

'
    Range("R5:R2000").Select
    Selection.NumberFormat = "@"
      
        With Sheets("PARTS").Range("R" & nr)
        .Value = x.Offset(, -1).Value
        .Font.FontStyle = "Bold"
        .Font.Color = 255
        LResult = Left("R", 5)
      End With
  
    End If
  Next x
  
End With


' selects column and AUTO-FIT-adjusts the width
With Sheets("PARTS")
  .Columns("E:E").AutoFit
  .Columns("P:R").AutoFit
  .Activate
  
  ' Macro1_adjustColumnWIDTH Macro
' selects column and adjusts the width TO A SPECIFIC WIDTH
'
    Columns("O:O").Select
    Selection.ColumnWidth = 25

End With
Application.ScreenUpdating = True

'RETURNS USER TO CELL A1 RATHER THAN LEAVING A COLUMN HIGLIGHTED
    Range("A1").Select

End Sub
 

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