Copy row if column contains specified number

Solved/Closed
Vince - Jun 23, 2010 at 08:23 AM
 vince - Jun 28, 2010 at 10:14 AM
Hello,
I have three columns of information, column C contains the site name and number e.g. Priory Park 4742. I currently use Find to search for the number, then copy and paste the row into new worksheet. Any ideas for code to automate this task searching the whole of column C and copying the row or rows that contain the entered number. It's important to copy all rows where the cell in column C has the number to check for duplicate numbers.

Thanks Vince Harper


2 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jun 23, 2010 at 09:57 AM
Could you please upload a sample file with sample data, Macro, CONDITIONAL FORMAT formula etc on some shared site like https://authentification.site , http://wikisend.com/ ,https://accounts.google.com/ServiceLogin?passive=1209600&continue=https://docs.google.com/&followup=https://docs.google.com/&emr=1 http://www.editgrid.com etc and post back here the link to allow better understanding of how it is now and how you foresee. Based on the sample book, could you re-explain your problem too
0
This is the code I have picked up from this site, but it does not paste into the next available row

in sheet2. It always pastes in row 1, overwriting previous paste


Sub Button1_Click()

Dim strsearch As String, lastline As Integer, tocopy As Integer

strsearch = CStr(InputBox("enter the string to search for"))
lastline = Range("A65536").End(xlUp).Row
j = 1

For i = 1 To lastline
For Each c In Range("C" & i)
If InStr(c.Text, strsearch) Then
tocopy = 1
End If
Next c
If tocopy = 1 Then
Rows(i).Copy Destination:=Sheets(2).Rows(j)
j = j + 1
End If
tocopy = 0
Next i

End Sub

help appreciated
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jun 24, 2010 at 06:18 PM
could you post your workbook with sample data and macro both on some share site ( to save time of creating a book on my own)
0
uploaded sample workbook to


Download link:
https://authentification.site/files/23128055/sample.xlsm
password:
sesefojicela

thanks vince harper
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jun 25, 2010 at 03:49 PM
Try this

Sub Button1_Click()

Dim strsearch As String, lastline As Integer, tocopy As Integer
Dim Cell As Range

    strsearch = CStr(InputBox("enter the string to search for"))
    
    lastline = Range("A65536").End(xlUp).Row
    
    Set Cell = Sheets("Sheet2").Cells.Find("*", Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
    
    If Cell Is Nothing Then
        j = 1
    Else
        j = Cell.Row + 1
    End If
    
    Set Cell = Nothing
    
    For i = 1 To lastline
    
        For Each c In Range("C" & i)
        
            If InStr(c.Text, strsearch) Then
                tocopy = 1
            End If
        
        Next c
        
        If tocopy = 1 Then
            Rows(i).Copy Destination:=Sheets(2).Rows(j)
            j = j + 1
        End If
        tocopy = 0
        
    Next i

End Sub
0
Exactly what I wanted

Thanks for your help

Vince Harper
0