Consulting

Results 1 to 5 of 5

Thread: Solved: VBA Index/Match Help

  1. #1

    Solved: VBA Index/Match Help

    This is my code, it works fine. The only problem is when I get a #N/A. How can I return a blank instead of #N/A?

    [VBA]Public Sub IndexMatch()
    Dim lastrow
    lastrow = Cells(Rows.Count, 1).End(xlUp).Row
    With Worksheets("Master").Range("c2:c" & lastrow)
    .Formula = "=INDEX(Daily!$A$2:$P$65536,MATCH(A2,Daily!$A$2:$A$65536,),2)"
    .Value = .Value
    End With

    End Sub[/VBA]

    Thank you.
    Last edited by Bob Phillips; 08-25-2011 at 04:00 PM. Reason: Added VBA tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub IndexMatch()
    Dim lastrow
    lastrow = Cells(Rows.Count, 1).End(xlUp).Row
    With Worksheets("Master").Range("c2:c" & lastrow)
    .Formula = "=IF(ISNA(MATCH(A2,Daily!$A$2:$A$65536,)),"",INDEX(Daily!$A$2:$P$65536,MATC H(A2,Daily!$A$2:$A$65536,),2))"
    .Value = .Value
    End With
    End Sub [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    [vba]

    Public Sub IndexMatch()
    Dim lastrow
    lastrow = Cells(Rows.Count, 1).End(xlUp).Row
    With Worksheets("Master").Range("c2:c" & lastrow)
    .Formula = "=IF(ISNA(MATCH(A2,Daily!$A$2:$A$65536,)),"",INDEX(Daily!$A$2:$P$65536,MATC H(A2,Daily!$A$2:$A$65536,),2))"
    .Value = .Value
    End With
    End Sub [/vba]
    I tried that one and a 1004 error comes up with that formula...

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Oops, my bad.

    [vba]

    Public Sub IndexMatch()
    Dim lastrow
    lastrow = Cells(Rows.Count, 1).End(xlUp).Row
    With Worksheets("Master").Range("c2:c" & lastrow)
    .Formula = "=IF(ISNA(MATCH(A2,Daily!$A$2:$A$65536,)),"""",INDEX(Daily!$A$2:$P$65536,MA TCH(A2,Daily!$A$2:$A$65536,),2))"
    .Value = .Value
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Works. Thanks. It took two tries because for some reason excel kept adding an extra " at the end. Thank you.

Posting Permissions

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