ADD-IN additional IF to Already Existing IF Function - VLOOKUP COMPARISON Add-in

Sphinx404

Board Regular
Joined
May 2, 2015
Messages
186
Office Version
  1. 365
Platform
  1. Windows
Good Morning accomplished VBA peers.

I'm running into a problem. I need to add-in an additional IF parameter and it's complicated. It touches on parts of VBA that I am not comfortable with and frankly, I don't know how to begin. This macro was essentially written by this board anyhow....

I've tried to outline the logic in the coding below, but I am unsure how to reach my goal. Any guidance would be greatly appreciated. Thanks guys.

Code:
Sub Macro4()

Dim myLastRow As Long
Dim myworksheet As Worksheet
Dim myLastRow2 As Long
Dim myWorksheet2 As Worksheet
Dim myWorksheet3 As Worksheet

Set myworksheet = Worksheets("HazShipper")
Set myWorksheet2 = Worksheets("DGbyFLT")
Set myWorksheet3 = Worksheets("UN3091")

lrow = myworksheet.Cells(myworksheet.Rows.Count, "A").End(xlUp).row
lrow2 = myWorksheet2.Cells(myWorksheet2.Rows.Count, "A").End(xlUp).row

For i = 2 To lrow

Set mycell = myworksheet.Range("AK" & i) [COLOR=#008000]'Contains Unit of Measure[/COLOR]
Set mycell2 = myworksheet.Range("AD" & i) [COLOR=#008000]'Contains UN/ID#[/COLOR]
Set mycell3 = myworksheet.Range("B" & i) [COLOR=#008000]'Contains static part #[/COLOR]

    If mycell.Value = "L" And mycell2.Value = "UN3363" Then [COLOR=#008000]'if UOM is L and UN/ID# is 3363 then[/COLOR]
        mycell.Offset(, 2).Formula = "=IFERROR(IF(AL" & i & "=AJ" & i & ",TRUE,FALSE),""Error"")" [COLOR=#008000]'if exact match then true, otherwise false, or error[/COLOR]
    Else
        mycell.Offset(, 2).Formula = "=IFERROR(IF(ABS(AJ" & i & " - AL" & i & ") <= AL" & i & "*0.1, ""Within Limit"", ""Outside Limit""),""Error"")" [COLOR=#008000]'do this function to see if weight comparison is within limits[/COLOR]
    End If
[COLOR=#ff0000]    'If mycell2.Value = "UN3091" Then[/COLOR]
[COLOR=#ff0000]        'vlookup mycell3 from 'myworksheet' and search for it in 'myworksheet'3 (starting A:D)[/COLOR]
[COLOR=#ff0000]            'when found in 'myworksheet3' compare the weight (column D) with the weight in 'myworksheet' (column AL)[/COLOR]
[COLOR=#ff0000]                'if weights match, then RETURN true, otherwise false - (RETURNs in 'myworksheet' column AM & i)[/COLOR]
    Next
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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