Cells.find

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
Hello All:

I have the following code snipit:

Code:
Dim X As Variant

X = Inputbox(--CM21158--)
'
Columns("A:A").Select
    Cells.Find(What:="&X&", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlDown).Activate

How can I use the find method to activate the cell with CM21158 in it?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try

Code:
Dim X As Variant
Dim Found As Range
X = InputBox("Enter Code")
'
Set Found = Columns("A").Find(What:=X, LookIn:=xlValues, LookAt:=xlPart)
If Not Found Is Nothing Then Found.Select
 
Upvote 0
Try

Code:
Dim X As Variant
Dim Found As Range
X = InputBox("Enter Code")
'
Set Found = Columns("A").Find(What:=X, LookIn:=xlValues, LookAt:=xlPart)
If Not Found Is Nothing Then Found.Select

Thanks for your reply Peter. This almost works except that it is copying not only the entered Code but other Codes as well? But much more closer that what I had previously? Can you tell me what may be causing the problem here is the entire code.

Code:
Sub Summarize()
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim X As Variant
Dim Found As Range

X = InputBox("Please Enter Customer Number to Search")
    
Worksheets.Add.Name = "Consolidate"

Set wbBook = ThisWorkbook

For Each wsSheet In wbBook.Sheets

If wsSheet.Name <> "Consolidate" Then wsSheet.Activate

Set Found = Columns("A").Find(What:=X, LookIn:=xlValues, LookAt:=xlPart)
If Not Found Is Nothing Then Found.Select

    ActiveCell.EntireRow.Copy Sheets("Consolidate").Range("A" & Rows.Count).End(xlUp)(2)


Next wsSheet



End Sub
 
Upvote 0
If you are entering the entire code to search for then try

Code:
Sub Summarize()
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim X As Variant
Dim Found As Range

X = InputBox("Please Enter Customer Number to Search")

Worksheets.Add.Name = "Consolidate"

Set wbBook = ThisWorkbook

For Each wsSheet In wbBook.Sheets

    If wsSheet.Name <> "Consolidate" Then
        wsSheet.Activate
        
        Set Found = Columns("A").Find(What:=X, LookIn:=xlValues, LookAt:=xlWhole)
        If Not Found Is Nothing Then Found.EntireRow.Copy Sheets("Consolidate").Range("A" & Rows.Count).End(xlUp)(2)
    End If

Next wsSheet



End Sub
 
Upvote 0
If you are entering the entire code to search for then try

Code:
Sub Summarize()
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim X As Variant
Dim Found As Range

X = InputBox("Please Enter Customer Number to Search")

Worksheets.Add.Name = "Consolidate"

Set wbBook = ThisWorkbook

For Each wsSheet In wbBook.Sheets

    If wsSheet.Name <> "Consolidate" Then
        wsSheet.Activate
        
        Set Found = Columns("A").Find(What:=X, LookIn:=xlValues, LookAt:=xlWhole)
        If Not Found Is Nothing Then Found.EntireRow.Copy Sheets("Consolidate").Range("A" & Rows.Count).End(xlUp)(2)
    End If

Next wsSheet



End Sub

Super!!! Thanks alot for your observations and help.
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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