Selecting cell from another sheet based on text value

Nikolamsnc

New Member
Joined
Jul 12, 2019
Messages
1
[FONT=&quot]I have one sheet with the range of cells with text in them, and another sheett with the range of cells with text in them and the number value next to the every cell.[/FONT]
[FONT=&quot]I need to choose the number value from the 2nd sheet based on the text from the 1st sheet matching some parts of text from the 2nd sheet.[/FONT]
[FONT=&quot]What functions should I combine in order to achieve that? Sorry if my post is confusing, and sorry for my English as well.[/FONT]
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
This macro assumes that your data is in Sheet1 and Sheet2 and that it is in columns A and B. Change the sheet names (in red) and the ranges (in blue) to suit your needs.
Code:
Sub copyNum()
    Application.ScreenUpdating = False
    Dim ws1 As Worksheet, ws2 As Worksheet, i As Long, v1 As Variant, v2 As Variant
    Set ws1 = Sheets("[COLOR="#FF0000"]Sheet1[/COLOR]")
    Set ws2 = Sheets("[COLOR="#FF0000"]Sheet2[/COLOR]")
    v1 = ws1.Range("[COLOR="#0000FF"]A2[/COLOR]", ws1.Range("[COLOR="#0000FF"]A[/COLOR]" & Rows.Count).End(xlUp)).Value
    v2 = ws2.Range("[COLOR="#0000FF"]A2[/COLOR]", ws2.Range("[COLOR="#0000FF"]A[/COLOR]" & Rows.Count).End(xlUp)).Resize(, 2).Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v2, 1)
            If Not .Exists(v2(i, 1)) Then
                .Add v2(i, 1), Nothing
            End If
        Next i
        For i = 1 To UBound(v1, 1)
            If .Exists(v1(i, 1)) Then
                ws1.Cells(i + 1, 2) = v2(i, 2)
            End If
        Next i
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Cross posted https://www.excelforum.com/excel-ge...l-from-another-sheet-based-on-text-value.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,224,745
Messages
6,180,699
Members
452,994
Latest member
Janick

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