Find Names in list based on Values VBA

Brentsa

Board Regular
Joined
Oct 3, 2013
Messages
118
Office Version
  1. 365
Platform
  1. Windows
I have a table with a list of names can be up to 1000 rows and values in 2 columns. So for small example:
Amal7175
Blackcurrant3838
Cantaloupe100100
Cempedak3737
Cherimoya (Custard Apple)8788
Elderberry7777
Feijoa8787
Fig5445
Grape99
Grapefruit2121
Guava2424
Loganberry7676
Lychee8680
Mangosteen9191
Melon7171
Miracle fruit9494
Mulberry7474
Pineberry4242
Plum414
Plumcot (or Pluot)8989
Salmonberry1515
Tayberry3836
Watermelon4040
Yuzu7575

I want to search for the following values so that I can get the names. The values can either be in Column B or C or both. I want to paste the numbers I'm looking for in column G and the results to appear in Column H and I
24
38
45
71
40
88

I would then like to see the results as follows with duplicate numbers highlighting the entire row.
24​
Guava
38​
Tayberry
38​
Blackcurrant
45​
Fig
71​
Melon
71​
Amal
40​
Watermelon
88​
Cherimoya (Custard Apple)
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Brentsa,

Not sure what you mean by "duplicate numbers highlighting the entire row" but this will do everything else you're asking for (assumes data starts at Row 2):

VBA Code:
Option Explicit
Sub Macro1()

    Dim clnMyItems As New Collection
    Dim varTemp As Variant
    Dim lngLastRow As Long, lngMyRow As Long, lngPasteRow As Long, lngArrayCount As Long
    Dim strMyNumbers() As String
   
    Application.ScreenUpdating = False
   
    lngLastRow = Cells(Rows.Count, "G").End(xlUp).Row
    For lngMyRow = 2 To lngLastRow
        lngArrayCount = lngArrayCount + 1
        ReDim Preserve strMyNumbers(1 To lngArrayCount) 'Append the current record to the 'strMyNumbers' array
        strMyNumbers(lngArrayCount) = Range("G" & lngMyRow)
    Next lngMyRow
   
    lngLastRow = Range("A:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For lngMyRow = 2 To lngLastRow
        On Error Resume Next
            If IsNumeric(Application.Match(CStr(Range("B" & lngMyRow)), strMyNumbers, 0)) = True Then
                clnMyItems.Add Range("B" & lngMyRow) & "|" & Range("A" & lngMyRow), CStr(Range("B" & lngMyRow) & "|" & Range("A" & lngMyRow))
            End If
            If IsNumeric(Application.Match(CStr(Range("C" & lngMyRow)), strMyNumbers, 0)) = True Then
                clnMyItems.Add Range("C" & lngMyRow) & "|" & Range("A" & lngMyRow), CStr(Range("C" & lngMyRow) & "|" & Range("A" & lngMyRow))
            End If
        On Error GoTo 0
    Next lngMyRow
   
    For Each varTemp In clnMyItems
        On Error Resume Next
            lngPasteRow = Range("H:I").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        On Error GoTo 0
        If lngPasteRow = 0 Then
            lngPasteRow = 2
        Else
            lngPasteRow = lngPasteRow + 1
        End If
        Range("H" & lngPasteRow).Value = Split(varTemp, "|")(0)
        Range("I" & lngPasteRow).Value = Split(varTemp, "|")(1)
    Next varTemp
   
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Last edited:
Upvote 0
Solution
Hi Brentsa,

Not sure what you mean by "duplicate numbers highlighting the entire row" but this will do everything else you're asking for (assumes data starts at Row 2):
I wanted to use something like conditional format to highlight which amounts are duplicated and with which products.

You VBA works on test thanks
 
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,528
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top