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.
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