Donneray

Information from classes and day to day stuff

FindInfo macro

Is below:

 

Sub FindInfo()
'
' FindInfo Macro
'
' Keyboard Shortcut: Ctrl+w
'
    Dim vendcode As String
    Dim itemcode As String
    Dim vendcodecurrent As String
    Dim itemcodecurrent As String
    Dim bolFoundItem As Boolean
    Dim strVendor As String
    Dim strBrand As String
    Dim strStubSpec As String
    Dim numVol_Eq
    Range("E2").Select
    ' Get what we are looking for
    vendcode = ActiveCell.Value
    ActiveCell.Offset(0, 1).Range("A1").Select
    itemcode = ActiveCell.Value
    ActiveCell.Offset(0, -1).Range("A1").Select
    Windows("prod_saltsnck.xlsx").Activate
    Range("H2").Select
    bolFoundItem = False
    i = 1
    Do While bolFoundItem = False
        ' Get what we are on
        vendcodecurrent = ActiveCell.Value
        ActiveCell.Offset(0, 1).Range("A1").Select
        itemcodecurrent = ActiveCell.Value
        ActiveCell.Offset(0, -1).Range("A1").Select
        'Have we found what we are looking for?
        If vendcode = vendcodecurrent Then
            If itemcode = itemcodecurrent Then
                bolFoundItem = True
                ActiveCell.Offset(0, -4).Range("A1").Select
                strVendor = ActiveCell.Value
                ActiveCell.Offset(0, 1).Range("A1").Select
                strBrand = ActiveCell.Value
                ActiveCell.Offset(0, 5).Range("A1").Select
                strStubSpec = ActiveCell.Value
                ActiveCell.Offset(0, 1).Range("A1").Select
                numVol_Eq = ActiveCell.Value
            End If
        End If
        ' Do what is required.
        If bolFoundItem = True Then
            Windows("SaltySnack_Sales.xlsx").Activate
            ActiveCell.Offset(0, 2).Range("A1").Select
            ActiveCell.Value = strVendor
            ActiveCell.Offset(0, 1).Range("A1").Select
            ActiveCell.Value = strBrand
            ActiveCell.Offset(0, 1).Range("A1").Select
            ActiveCell.Value = strStubSpec
            ActiveCell.Offset(0, 1).Range("A1").Select
            ActiveCell.Value = numVol_Eq
            'Move back
            ActiveCell.Offset(0, -5).Range("A1").Select
            'Grab the next value(s)
            ActiveCell.Offset(1, 0).Range("A1").Select
            vendcode = ActiveCell.Value
            ActiveCell.Offset(0, 1).Range("A1").Select
            itemcode = ActiveCell.Value
            ActiveCell.Offset(0, -1).Range("A1").Select
            'Reset
            Windows("prod_saltsnck.xlsx").Activate
            Range("H2").Select
            bolFoundItem = False
            i = 1
            ' Again!
        Else
            ActiveCell.Offset(1, 0).Range("A1").Select
        End If
        If i > 18000 Then
            bolFoundItem = True
            Windows("SaltySnack_Sales.xlsx").Activate
            ActiveCell.Offset(0, 2).Range("A1").Select
            ActiveCell.Value = "Unknown"
            ActiveCell.Offset(0, 1).Range("A1").Select
            ActiveCell.Value = "Unknown"
            ActiveCell.Offset(0, 1).Range("A1").Select
            ActiveCell.Value = "Unknown"
            ActiveCell.Offset(0, 1).Range("A1").Select
            ActiveCell.Value = "Unknown"
            'Move back
            ActiveCell.Offset(0, -5).Range("A1").Select
            'Grab the next value(s)
            ActiveCell.Offset(1, 0).Range("A1").Select
            vendcode = ActiveCell.Value
            ActiveCell.Offset(0, 1).Range("A1").Select
            itemcode = ActiveCell.Value
            ActiveCell.Offset(0, -1).Range("A1").Select
            'Reset
            Windows("prod_saltsnck.xlsx").Activate
            Range("H2").Select
            bolFoundItem = False
            i = 1
            ' Again!
        End If
        If Len(Trim(vendcode)) < 2 Then
            If Len(Trim(itemcode)) < 2 Then
                Exit Sub
            End If
        End If
        i = i + 1
   Loop
End Sub