Want to Display All Items Using Find Exact Match

GWee

New Member
Joined
Nov 8, 2005
Messages
24
I would like to find all the numbers that are the same and display them to review and put them in a separate sheet for print. Does anybody have the code for this? Using UserForm for this!

Thanks! :o
 
Hello, GWee,
please care of providing examples of what you're trying to do
as I read this, you are going to put for instance 50 times the same number in another sheet
find all the numbers that are the same and display them
so there is missing something to me or to your explanation

kind regards,
Erik
 
Upvote 0
Ok I'll Try

Column A has 5 digit numbers some have the same number but different information throughout the row .

I need to pick up all the matching numbers in Column A to get the different info from those rows.

Thankyou for your help! :-?
 
Upvote 0
Code:
Option Explicit

Sub copy_rows()
Dim c As Range
Dim TextToFind As String
Dim firstAddress As String
TextToFind = TextBox1 'or whatever control on your userform
With Sheets(1).Columns(1)
    Set c = .Find(TextToFind, LookIn:=xlValues, LookAt:=xlWhole)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
            c.EntireRow.Copy Sheets(2).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
End With
End Sub

faster code: if a lot of rows to do
Code:
Option Explicit

Sub copyrows_if()
'Erik Van Geit
'040223
Dim rng As Range
Dim LC As Integer   'last column
Dim LR As Long      'last row
Dim TextToFind As String

Const HR As Long = 1    'header row (first data = HR + 1)
TextToFind = 123
With Sheets(1)
LR = .Cells(Rows.Count, 1).End(xlUp).Row
LC = .Cells.Find("*", .[A1], xlFormulas, xlPart, xlByColumns, xlPrevious, False, False).Column
Set rng = .Range(.Cells(2, LC + 1), .Cells(LR, LC + 1))
End With

    With rng
        .FormulaR1C1 = "=IF(RC1=" & TextToFind & ",1,0)"
        .Copy
        .PasteSpecial Paste:=xlValues
    End With
    
With Sheets(1)
.Range(.Cells(HR, 1), .Cells(LR, LC + 1)).AutoFilter Field:=LC + 1, Criteria1:="1"
.Range(.Cells(HR + 1, 1), .Cells(LR, LC)).Copy Sheets(2).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
End With

Sheets(1).Range("A1").AutoFilter
rng.ClearContents
End Sub
 
Upvote 0
GWee

Do you need to use code? And do you need to put the information on another sheet?

Could you just use Data|Filter|AutoFilter then filter column A for the number you want and print the results?

If you do want the information on another sheet, could you filter as described above, copy the resultant display and paste on the other sheet?
 
Upvote 0
Hi, guys,
there is some "overkill" in my second method
(using autofilter)
this was updated from another file where the condition was more complicated, hence the extra column (which you will only see interupting the code), which isn't needed in fact here :huh:
nevermind, it is fast and easy to use

if you would like to get the update, just ask ...
(no time left by now)

kind regards,
Erik
 
Upvote 0
Thanks Peter For Your Comment!! My reply....

Peter_SSs said:
GWee

Do you need to use code? And do you need to put the information on another sheet?

Could you just use Data|Filter|AutoFilter then filter column A for the number you want and print the results?

If you do want the information on another sheet, could you filter as described above, copy the resultant display and paste on the other sheet?
I'm using a userform to get the information and then edit the textboxes, checkboxes, option boxes. I click on ENTER. Then if I see a problem/errors I would like to Undo. I somewhat found a start...What do you think if I can use:

Application.OnUndo "The Last Macro", "MyUndoMacro"

How would I put a command button on a userform using part/whole of this type of code?

Thanks so much for the help! :-D
 
Upvote 0
Gwee,
finally I see what you were asking here :-)
http://www.mrexcel.com/board2/viewtopic.php?p=867706&highlight=#867706
let's undo the entire operation (method mentioned already in the other thread)
to test used just clearcontents
Code:
Option Explicit

Public ThisSheet As Worksheet
Public ThisShName As String
Public TryOutSheet As Worksheet
Public Const BackupShName As String = "backupsheet"

Sub test()
'Erik Van Geit
'051122

Set ThisSheet = ActiveSheet
ThisShName = ThisSheet.Name

Application.ScreenUpdating = False

    With ThisSheet
    .Copy After:=Sheets(Sheets.Count)
        Application.DisplayAlerts = False
        .Name = BackupShName
        Application.DisplayAlerts = True
    .Visible = xlSheetVeryHidden
    End With

Set TryOutSheet = ActiveSheet
TryOutSheet.Name = ThisShName

Application.ScreenUpdating = True

yourmacro

End Sub

Sub undo_this()
    With Application
    .ScreenUpdating = False
        ThisSheet.Visible = True
        .DisplayAlerts = False
        TryOutSheet.Delete
        .DisplayAlerts = True
        ThisSheet.Name = ThisShName
    .ScreenUpdating = True
    End With
End Sub

Sub yourmacro()
Cells.ClearContents
End Sub
first run the test
then "undo_this"
in between you can do other operations which will all be "undone"
the code is "quick-made" not tested in detail, but seems to work

kind regards,
Erik
 
Upvote 0

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