Find text from Cell in a Column and Retrieve row # and paste the information.

Shreesurya

Board Regular
Joined
Jul 7, 2014
Messages
50
Please help!

I want to search a text from a cell in a column and find out Row # and paste the row number in next sheet and copy paste whole row next to that.

Eg.
Text StringRow #Table infoTable Info
Account2
EscrowAccountStatementDate

<tbody>
</tbody>
date on which escrow statements are sent

<tbody>
</tbody>
Account3
EscrowAccountComputeDate

<tbody>
</tbody>
Date on which escrow account is computed

<tbody>
</tbody>

<tbody>
</tbody>

Below is the raw data for your reference.

Note: It should split the text from the cell and search, Example: in first cell it says Institution Number - so it should be 3 way search like below. and loop for every cell in A Column and search in both B & C Column.

1. Institution
2. Number
3. Institution Number

EDW Field DescriptionCopasysfieldnameField description
Institution NumberEscrowAccountComputeDateDate on which escrow account is computed
Account NumberEscrowAccountStatementDatedate on which escrow statements are sent
Close CodeEscrowAdvanceBalanceEscrow advance balance amount
Credit Insurance Payment AmountEscrowAnalysisDateEscrow analysis date
Principal BalanceEscrowAnalysisDisbursmentAmountEscrow Disbursement amount
C Info Seg IndrEscrowAnalysisShortAmountShortage amount in escrow analysis
Escrow BalanceEscrowBalanceEscrow balance amount
Payoff Penalty FlagEscrowBorrowerContactDateEscrow borrower contact data
Last Activity DateEscrowCityTaxAmountEscrow city tax amount
Last Activity Date NbrEscrowCityTaxDateEscrow city tax date

<colgroup><col><col><col></colgroup><tbody>
</tbody>


In need of desperate Help.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Put your data in Sheet1 like this:

Excel Workbook
ABC
1EDW Field DescriptionCopasysfieldnameField description
2Institution NumberEscrowAccountComputeDateDate on which escrow account is computed
3Account NumberEscrowAccountStatementDatedate on which escrow statements are sent
4Close CodeEscrowAdvanceBalanceEscrow advance balance amount
5Credit Insurance Payment AmountEscrowAnalysisDateEscrow analysis date
6Principal BalanceEscrowAnalysisDisbursmentAmountEscrow Disbursement amount
7C Info Seg IndrEscrowAnalysisShortAmountShortage amount in escrow analysis
8Escrow BalanceEscrowBalanceEscrow balance amount
9Payoff Penalty FlagEscrowBorrowerContactDateEscrow borrower contact data
10Last Activity DateEscrowCityTaxAmountEscrow city tax amount
11Last Activity Date NbrEscrowCityTaxDateEscrow city tax date
sheet1





In Sheet2, in cell B1 put the text to search, the result will be like this:


Excel Workbook
ABCD
1Text:Institution Number
2
3Text StringRow #Table infoTable Info
4Institution Number2EscrowAccountComputeDateDate on which escrow account is computed
5Account Number3EscrowAccountStatementDatedate on which escrow statements are sent
Sheet2





Try this code:

Code:
Sub Find_Text()
    Dim sh1 As Worksheet, sh2 As Worksheet
    Dim wText As String, wTexts As New Collection, wpaso As Variant
    Dim b As Range, r As Range, celda As String
    Dim i As Double, j As Double
    '
    Set sh1 = Sheets("Sheet1")
    Set sh2 = Sheets("Sheet2")
    
    sh2.Rows("4:" & Rows.Count).ClearContents
    sh2.Columns("Z").ClearContents
    
    wText = sh2.Range("B1")
    If wText = "" Then
        MsgBox "Enter a text"
        Exit Sub
    End If
    
    wTexts.Add wText
    wpaso = Split(wText, " ")
    For i = LBound(wpaso) To UBound(wpaso)
        wTexts.Add wpaso(i)
    Next
    
    j = 4
    For i = 1 To wTexts.Count
        Set r = sh1.Columns("A")
        Set b = r.Find(wTexts(i), LookAt:=xlPart, LookIn:=xlValues)
        If Not b Is Nothing Then
            celda = b.Address
            Do
                'detalle
                If sh2.Cells(b.Row, "Z").Value = "" Then
                
                    sh2.Cells(j, "A").Value = sh1.Cells(b.Row, "A").Value
                    sh2.Cells(j, "B").Value = b.Row
                    sh2.Cells(j, "C").Value = sh1.Cells(b.Row, "B").Value
                    sh2.Cells(j, "D").Value = sh1.Cells(b.Row, "C").Value
                    sh2.Cells(b.Row, "Z").Value = "x"
                    j = j + 1
                    
                End If
                Set b = r.FindNext(b)
            Loop While Not b Is Nothing And b.Address <> celda
        End If
    Next
    sh2.Columns("Z").ClearContents
    
    MsgBox "Finish"
    
End Sub
 
Upvote 0
I still do not understand, you could explain step by step a couple of examples of what you sent in the file, that is:
- I go to the sheet x
- I take the data y
- I look for it in the sheet z in the column w
- If I find it I take the data from column xx of the sheet yy and I paste it on the sheet zz in the column ww

Change x, y, z, w, xx, yy , zz , ww by the real data, using your example.
 
Upvote 0
I am sorry for the confusion Dante.

Below are the steps which might help you.

Step 1 - Go to Raw Data Sheet, Pick data from Cell A2 and Search in B & C Column
Step 2 - If found copy the Whole row and paste it in next Page "Result"
Step 3 - then Go to cell A3 in Raw data and repeat above steps and it should loop to next cells from A Column.

While Pasting the row. it should also paste the search string in the same row and row number as a reference.

Hope this helps... and thank you so much for spending time for this..
 
Upvote 0
Well, you did not explain with sample data, but try the following:

Code:
Sub Find_Text()
    Dim sh1 As Worksheet, sh2 As Worksheet
    Dim wText As String, wTexts As New Collection, wpaso As Variant
    Dim b As Range, r As Range, celda As String
    Dim i As Double, j As Double, lr As Double, w As Double
    '
    Set sh1 = Sheets("Raw Data")
    Set sh2 = Sheets("Result")
    
    sh2.Rows("2:" & Rows.Count).ClearContents
    'sh2.Columns("Z").ClearContents
    
    j = 2
    lr = sh1.Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To lr
        
        'sh2.Columns("Z").ClearContents
        wText = sh1.Cells(i, "A")
        wTexts.Add wText
        wpaso = Split(wText, " ")
        For w = LBound(wpaso) To UBound(wpaso)
            wTexts.Add wpaso(w)
        Next
        
        For h = 1 To wTexts.Count
            Set r = sh1.Columns("B:C")
            que = wTexts(h)
            Set b = r.Find(wTexts(h), LookAt:=xlPart, LookIn:=xlValues)
            If Not b Is Nothing Then
                celda = b.Address
                Do
                    'detalle
                    If b.Row > 1 Then
                        'If sh2.Cells(b.Row, "Z").Value = "" Then
                        
                            sh2.Cells(j, "A").Value = wTexts(h) & " (" & sh1.Cells(i, "A").Value & ")"
                            sh2.Cells(j, "B").Value = b.Row
                            sh2.Cells(j, "C").Value = sh1.Cells(b.Row, "B").Value
                            sh2.Cells(j, "D").Value = sh1.Cells(b.Row, "C").Value
                            'sh2.Cells(b.Row, "Z").Value = "x"
                            j = j + 1
                            
                        'End If
                    End If
                    Set b = r.FindNext(b)
                Loop While Not b Is Nothing And b.Address <> celda
            End If
        Next
        
        For y = wTexts.Count To 1 Step -1
            wTexts.Remove (y)
        Next
        
    Next
    'sh2.Columns("Z").ClearContents
    
    MsgBox "Finish"
    
End Sub
 
Upvote 0
I'm glad to help you. I appreciate your kind comments.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,558
Latest member
aivin

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