+ Reply to Thread
Results 1 to 3 of 3

Thread: Problems with For Next...

  1. #1
    Registered User
    Join Date
    07-01-2010
    Location
    Costa Rica
    MS-Off Ver
    Excel 2007
    Posts
    5

    Problems with For Next...

    Hi
    (sorry for my english) I got a macro, but not run when i put some code in there...
    this is my code

    *****************
    Function Wlookup(wLookup_array As Variant, wTable_array As Range, wCol As Integer, wType As Boolean)
    
    Dim i As Range
    
    For Each i In wLookup_array
    
        Dim Val As String
        Val = WorksheetFunction.VLookup(("*" & i.Value & "*"), wTable_array, wCol, wType)
        
        If Not Val Is Nothing Then
        Wlookup = Val
        Exit For
        End If
    
    Next i
    
    Wlookup = Val
    
    End Function

    i dont know why not loop with
    Dim Val As String
        Val = WorksheetFunction.VLookup(("*" & i.Value & "*"), wTable_array, wCol, wType)"
    Here is the file...
    http://www.excelforum.com/attachment...1&d=1278012135

    I really appreciate any help...
    Attached Files Attached Files
    Last edited by Leith Ross; 07-01-2010 at 03:49 PM. Reason: Added Code Tags

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    3,004

    Re: Problems with For Next...

    Try this variation

    Function Wlookup(wLookup_array As Variant, wTable_array As Range, wCol As Integer, wType As Boolean)
    Dim Val As Variant
    Dim i As Range
    
    For Each i In wLookup_array
        Val = InStr(wTable_array.Value, i.Value)
        
        If Val > 0 Then
        Wlookup = i.Offset(0, wCol)
        Exit Function
        End If
    
    Next i
    
    Wlookup = "err"
    
    End Function
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

  3. #3
    Registered User
    Join Date
    07-01-2010
    Location
    Costa Rica
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Problems with For Next...

    Thanks so much mrice!!! It works... I'll part of that code.... Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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