+ Reply to Thread
Results 1 to 1 of 1

How to use VBA to perform Index/MATCH for multiple Criteria as well as ignore blank cells

  1. #1
    Registered User
    Join Date
    10-16-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    1

    How to use VBA to perform Index/MATCH for multiple Criteria as well as ignore blank cells

    Hi,
    I need a big help here
    I'm required to complete a report which need to meet multiple criteria by using macro scripts.
    This report previously only require to match one criteria. However, now it need to read multiple criteria in the range that contains more than one criteria. For example if Column C contains supplier name - Kelly with another criteria in Column E3 = return IFSBilling as a result else if just only contains Kelly return "Contingent Workers" as result.
    There are 2 additional column to vlookups as well.
    Can anyone help me here? seriously i need a solution now. Let me know if more clarification needed.

    Many thanks in advance

    VBA name : LookupValues

    The GLAP result Column AX is where the result is returning by reading the data from.

    Dim colwithTextSAP As Integer 'will store the column number of the text to be checked in the SAP data sheet
    Dim colToPlaceFoundValue As Integer 'will store the column number where the value found will be place
    Dim colwithTextLookup As Integer 'will store the column number of the text to be looked for in the lookup sheet
    Dim firstRowSAP As Integer 'will store first data row in SAP data file
    Dim lastRowSAP As Integer 'will store last row in SAP data file
    Dim lastRowLookupVar As Integer 'will store last row in lookupValuesSheetName
    Dim GLAPSheetName As String 'will store SAP Data sheet name
    Dim lookupValuesSheetName As String 'will store the sheet name which has the lookup values
    Dim firstRowLookupSheet As Integer 'will store first row with data in the lookup sheet
    Dim textToSearchIn As String 'string to search in SAP file
    Dim textToSearchInLookupValue As String 'string that we would like to check if exists in the textToSearchIn
    Dim valueFoundToUpdateField As String 'once search string found, this variant will store the value that was found to be placed in the category field in the SAP data sheet
    Dim colCategoryInLookupValueSheet As Integer ' column number for category column number in the lookup value sheet
    Dim sapCurrRow, lookupCurrRow As Integer 'current row to be used for SAP and Lookup loops
    Dim mypost As Variant


    GLAPSheetName = "GLAP"
    lookupValuesSheetName = "LookupValues"


    'store variants for lookupValuesSheetName
    Sheets(lookupValuesSheetName).Select
    firstRowLookupSheet = 3 'first row with data in the lookup sheet
    colwithTextLookup = 4 'column number with text to search for in the lookup sheet
    colCategoryInLookupValueSheet = 6 ' category column number in the lookup value sheet
    'find last row in lookupValuesSheetName
    Range("F1").Select
    Selection.End(xlDown).Select
    lastRowLookupVar = Selection.Row


    'store variants for GLAPSheetName
    Sheets(GLAPSheetName).Select
    firstRowSAP = 3 'first row with data in GLAP data sheet
    colwithTextSAP = 18 'column number of text to be checked
    colToPlaceFoundValue = 50 'column number to place the found value
    'find last row in SAP data file
    Range("AQ2").Select
    Selection.End(xlDown).Select
    lastRowSAP = Selection.Row


    'outer loop, review each line in SAP data sheet
    For sapCurrRow = firstRowSAP To lastRowSAP
    Sheets(GLAPSheetName).Select 'get value to look in from SAP sheet name
    textToSearchIn = Cells(sapCurrRow, colwithTextSAP)
    If Len(textToSearchIn) > 0 Then 'if textToSearchIn is not blank, will search for match in lookupvalue sheet
    'Inner loop, until find a match search in the lookup values sheet for a match in order to add the category
    Sheets(lookupValuesSheetName).Select 'search in lookup values sheet
    For lookupCurrRow = firstRowLookupSheet To lastRowLookupVar
    textToSearchInLookupValue = Cells(lookupCurrRow, colwithTextLookup)

    Mypos = InStr(1, textToSearchIn, textToSearchInLookupValue)
    If (Mypos <> 0) And (Len(textToSearchInLookupValue) <> 0) Then 'if found the subsrting and the substring is not blank

    valueFoundToUpdateField = Cells(lookupCurrRow, colCategoryInLookupValueSheet).Value 'get the value to place in the Category column
    lookupCurrRow = lastRowLookupVar + 1 'if found exit inner loop to move to next row in SAP data file
    Sheets(GLAPSheetName).Select 'get value to look in from SAP sheet name
    Cells(sapCurrRow, colToPlaceFoundValue).Value = valueFoundToUpdateField 'place the found value in the SAP sheet
    End If
    'if not found (meaning Mypos=0) then inner loop will continue

    Next lookupCurrRow
    lookupCurrRow = 0 'for next run of innter loop
    End If 'If length(textToSearchIn)>0

    Next sapCurrRow 'exit outer loop to review each line in SAP data sheet
    Attached Files Attached Files
    Last edited by sandyhx88; 11-05-2014 at 11:25 AM. Reason: typo error

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I want to exclude blank cell in index match formula with multiple criteria
    By NOOR8225 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 09-16-2013, 06:51 AM
  2. Replies: 5
    Last Post: 05-18-2013, 07:49 PM
  3. [SOLVED] An INDEX MATCH formula has blank cell - need to ignore or delete
    By rls231 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-26-2013, 11:13 PM
  4. [SOLVED] Autofilter with multiple criteria - how to ignore blank criteria
    By MOONDRIFT47 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-31-2012, 12:20 PM
  5. Replies: 4
    Last Post: 07-18-2012, 02:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1