Help to Adjust lookup and copy script

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
This code is to take the user input from the InputBox and then compare them with the last two characters of the contents of two consecutive rows. Then copy all those rows with the match.

But the version down here only deals with it when the match is found in the first two rows of the dataset. And it only copies the matched cell values instead of the entire data in the row. Here the data copied are pasted horizontally. I want it done vertically

Can someone help fix it for me?

Code:
Sub FindPartialMatches(ByVal Text As String)


    Dim RngDst  As Range
    Dim RngSrc  As Range
    Dim RngEnd  As Range
    Dim WksDst  As Worksheet
    Dim WksSrc  As Worksheet
    
        Set WksSrc = ActiveSheet
        Set WksDst = Worksheets("Sheet2")
        
        Set RngDst = WksDst.Range("A1")
        
        Set RngSrc = WksSrc.Range("B1:H" & WksSrc.UsedRange.Rows.Count)
        Set RngEnd = RngSrc.Find("*", RngSrc.Cells(RngSrc.Rows.Count, 1), xlValues, xlWhole, xlByRows, xlPrevious, False, False, False)
        Set RngSrc = RngSrc.Resize(RowSize:=RngEnd.Row - RngSrc.Row + 1)
        
        Addx = RngSrc.Address
        
        vInputs = Split(Text, ",")
        
        With RngSrc
            For c = 1 To .Columns.Count
                For r = 1 To .Rows.Count - 1
                    If .Cells(r, c) Like "*" & vInputs(0) Then
                        If .Cells(r + 1, c) Like "*" & vInputs(1) Then
                            RngDst.Value = .Cells(r, c)
                            RngDst.Offset(0, 1).Value = .Cells(r + 1, c)
                            Set RngDst = RngDst.Offset(1, 0)
                        End If
                    End If
                Next r
            Next c
        End With
        
End Sub


Sub Test  ()
Dim vInputs 
vInputs = InputBox  ("Enter 2 numbers separated by comma ")
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Still need help with this.

Can someone confirm it is possible?

Regards
Kelly
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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