+ Reply to Thread
Results 1 to 3 of 3

VLookUp Error Handling Needed

  1. #1
    Arturo
    Guest

    VLookUp Error Handling Needed

    I have a Vlookup table.
    Im looping through a column of letters.
    The value of cell F2 is inserted into named range _In.
    Named range _Out returns what that letter gets converted to.
    If there is not a match from the Vlookup, Im not sure how to handle the
    error.
    The desired outcome is whatever the value not matching up (varA) should
    remain as is.
    Sincerely,
    Arturo


    Sub Convert()
    Dim myRange As Range
    Dim rO As Integer
    Dim coL As Integer
    Dim LoopCount_C As Integer
    Dim LoopCount_R As Integer
    Dim VarA As Variant
    Dim VarB As Variant


    ''' Rows("1:9").Delete Shift:=xlUp
    Range("A1").Select
    Set myRange = ActiveCell.CurrentRegion
    rO = myRange.Rows.Count - 1
    coL = myRange.Columns.Count
    Range("F2").Select
    For LoopCount_C = 1 To coL
    For LoopCount_R = 1 To rO
    VarA = ActiveCell.Value
    Range("_In").Value = VarA
    VarB = Range("_Out").Value

    'Error Handling Needed.
    'If no match is found then
    'ActiveCell.Value = VarA

    ActiveCell.Value = VarB
    ActiveCell.Offset(1, 0).Select
    Next
    ActiveCell.Offset(-rO, 1).Select
    Next

    End Sub

  2. #2
    Tom Ogilvy
    Guest

    RE: VLookUp Error Handling Needed


    For LoopCount_R = 1 To rO
    VarA = ActiveCell.Value
    Range("_In").Value = VarA
    VarB = Range("_Out").Value
    if not iserror(varB) then
    ActiveCell.Value = VarB
    End if
    ActiveCell.Offset(1, 0).Select
    Next

    The activecell already has the value of varA, so no action is required if
    there is no replacement value.

    --
    Regards,
    Tom Ogilvy



    "Arturo" wrote:

    > I have a Vlookup table.
    > I’m looping through a column of letters.
    > The value of cell F2 is inserted into named range “_In”.
    > Named range “_Out” returns what that letter gets converted to.
    > If there is not a match from the Vlookup, I’m not sure how to handle the
    > error.
    > The desired outcome is whatever the value not matching up (varA) should
    > remain as is.
    > Sincerely,
    > Arturo
    >
    >
    > Sub Convert()
    > Dim myRange As Range
    > Dim rO As Integer
    > Dim coL As Integer
    > Dim LoopCount_C As Integer
    > Dim LoopCount_R As Integer
    > Dim VarA As Variant
    > Dim VarB As Variant
    >
    >
    > ''' Rows("1:9").Delete Shift:=xlUp
    > Range("A1").Select
    > Set myRange = ActiveCell.CurrentRegion
    > rO = myRange.Rows.Count - 1
    > coL = myRange.Columns.Count
    > Range("F2").Select
    > For LoopCount_C = 1 To coL
    > For LoopCount_R = 1 To rO
    > VarA = ActiveCell.Value
    > Range("_In").Value = VarA
    > VarB = Range("_Out").Value
    >
    > 'Error Handling Needed.
    > 'If no match is found then
    > 'ActiveCell.Value = VarA
    >
    > ActiveCell.Value = VarB
    > ActiveCell.Offset(1, 0).Select
    > Next
    > ActiveCell.Offset(-rO, 1).Select
    > Next
    >
    > End Sub


  3. #3
    Arturo
    Guest

    RE: VLookUp Error Handling Needed

    THANK You Tom!

    "Tom Ogilvy" wrote:

    >
    > For LoopCount_R = 1 To rO
    > VarA = ActiveCell.Value
    > Range("_In").Value = VarA
    > VarB = Range("_Out").Value
    > if not iserror(varB) then
    > ActiveCell.Value = VarB
    > End if
    > ActiveCell.Offset(1, 0).Select
    > Next
    >
    > The activecell already has the value of varA, so no action is required if
    > there is no replacement value.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    > "Arturo" wrote:
    >
    > > I have a Vlookup table.
    > > I’m looping through a column of letters.
    > > The value of cell F2 is inserted into named range “_In”.
    > > Named range “_Out” returns what that letter gets converted to.
    > > If there is not a match from the Vlookup, I’m not sure how to handle the
    > > error.
    > > The desired outcome is whatever the value not matching up (varA) should
    > > remain as is.
    > > Sincerely,
    > > Arturo
    > >
    > >
    > > Sub Convert()
    > > Dim myRange As Range
    > > Dim rO As Integer
    > > Dim coL As Integer
    > > Dim LoopCount_C As Integer
    > > Dim LoopCount_R As Integer
    > > Dim VarA As Variant
    > > Dim VarB As Variant
    > >
    > >
    > > ''' Rows("1:9").Delete Shift:=xlUp
    > > Range("A1").Select
    > > Set myRange = ActiveCell.CurrentRegion
    > > rO = myRange.Rows.Count - 1
    > > coL = myRange.Columns.Count
    > > Range("F2").Select
    > > For LoopCount_C = 1 To coL
    > > For LoopCount_R = 1 To rO
    > > VarA = ActiveCell.Value
    > > Range("_In").Value = VarA
    > > VarB = Range("_Out").Value
    > >
    > > 'Error Handling Needed.
    > > 'If no match is found then
    > > 'ActiveCell.Value = VarA
    > >
    > > ActiveCell.Value = VarB
    > > ActiveCell.Offset(1, 0).Select
    > > Next
    > > ActiveCell.Offset(-rO, 1).Select
    > > Next
    > >
    > > End Sub


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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