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. [TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Text String[/TD]
[TD]Row #[/TD]
[TD]Table info[/TD]
[TD]Table Info[/TD]
[/TR]
[TR]
[TD]Account[/TD]
[TD]2[/TD]
[TD][TABLE="width: 237"]
<tbody>[TR]
[TD="class: xl65, width: 237"]EscrowAccountStatementDate[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 279"]
<tbody>[TR]
[TD="class: xl65, width: 279"]date on which escrow statements are sent[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]Account[/TD]
[TD]3[/TD]
[TD][TABLE="width: 237"]
<tbody>[TR]
[TD="class: xl65, width: 237"]EscrowAccountComputeDate[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 279"]
<tbody>[TR]
[TD="class: xl65, width: 279"]Date on which escrow account is computed[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

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

[TABLE="class: grid, width: 740"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]EDW Field Description[/TD]
[TD]Copasysfieldname[/TD]
[TD]Field description[/TD]
[/TR]
[TR]
[TD]Institution Number[/TD]
[TD]EscrowAccountComputeDate[/TD]
[TD]Date on which escrow account is computed[/TD]
[/TR]
[TR]
[TD]Account Number[/TD]
[TD]EscrowAccountStatementDate[/TD]
[TD]date on which escrow statements are sent[/TD]
[/TR]
[TR]
[TD]Close Code[/TD]
[TD]EscrowAdvanceBalance[/TD]
[TD]Escrow advance balance amount [/TD]
[/TR]
[TR]
[TD]Credit Insurance Payment Amount[/TD]
[TD]EscrowAnalysisDate[/TD]
[TD]Escrow analysis date[/TD]
[/TR]
[TR]
[TD]Principal Balance[/TD]
[TD]EscrowAnalysisDisbursmentAmount[/TD]
[TD]Escrow Disbursement amount [/TD]
[/TR]
[TR]
[TD]C Info Seg Indr[/TD]
[TD]EscrowAnalysisShortAmount[/TD]
[TD]Shortage amount in escrow analysis[/TD]
[/TR]
[TR]
[TD]Escrow Balance[/TD]
[TD]EscrowBalance[/TD]
[TD]Escrow balance amount[/TD]
[/TR]
[TR]
[TD]Payoff Penalty Flag[/TD]
[TD]EscrowBorrowerContactDate[/TD]
[TD]Escrow borrower contact data[/TD]
[/TR]
[TR]
[TD]Last Activity Date[/TD]
[TD]EscrowCityTaxAmount[/TD]
[TD]Escrow city tax amount[/TD]
[/TR]
[TR]
[TD]Last Activity Date Nbr[/TD]
[TD]EscrowCityTaxDate[/TD]
[TD]Escrow city tax date[/TD]
[/TR]
</tbody>[/TABLE]


In need of desperate Help.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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