macro to find a name in a sheet

Firecop1348

Board Regular
Joined
Oct 24, 2009
Messages
101
Im using this macro to find a number within my sheet. I need to change it to be able to find a NAME within a sheet of my workbook. I thought it would be easy, but I just cant seem to make it happen.
Any help would be nice . ... AGAIN. LOL

HTML:
Sub Find_the_Number()
Dim ws As Worksheet, ctr
ctr = 0
theNum = InputBox("Please enter the number to seek.", _
"Search Criteria")
For Each ws In ActiveWorkbook.Worksheets
ws.Select
For Each cell In ws.UsedRange
cell.Select
If ActiveCell.Value = Val(theNum) Then
ctr = 1
Exit Sub
End If
Next
Next
Sheets("Main").Select
    ActiveWindow.SmallScroll Down:=-24
    Range("G1").Select
If ctr = 0 Then
MsgBox "No sheet contains the the number: " & _
theNum, vbOKOnly, "Not Found"
Else
End If
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I think a little more detail would be helpful. Your code searches all worksheets but you said you were looking for the name "within a sheet of my workbook"... do you know the sheet name the name you are looking for is on or not (if so, tell us what it is)? More important is are you looking for this name all by itself within a cell or is it embedded within other text in the cell its in? Also, do you really need to do this with a macro (there is always the Edit/Find option)?
 
Upvote 0
First I guess I dont really have to do it with a macro but its nice just to click on a button enter the info you are looking for and have it right there. I guess I just want a little fancy workbook.
Second, the workbook is for customer work orders, If someone comes in and needs something done instead of making out another work order for them I want to be able to search for their name and if I have a work order for them from the past I can just add to it. If I dont have one for them I make a new one and they are now in my workbook.

The number macro I posted works great, I can type in a number (phone, date) ect and it will find it or tell me no record found.
thats what I would like with it but looking for a name within the workbook sheets. The name could be on any sheet within the entire book.
I hope this is what you were looking for.
thanks
 
Upvote 0
See if this macro does what you want...
Code:
Sub FindName()
  Dim NameToFind As String, Cell As Range, FirstUsedCell As Range, WS As Worksheet
  NameToFind = InputBox("What name are you looking for?")
  On Error Resume Next
  Application.ScreenUpdating = False
  For Each WS In Worksheets
    WS.Activate
    WS.UsedRange.Cells(1).Select
    If Err.Number Then
      Err.Clear
      GoTo Continue
    End If
    Set Cell = WS.UsedRange.Cells.Find(NameToFind, ActiveCell, xlValues, xlPart, , xlNext, False)
    If Not Cell Is Nothing Then
      Cell.Select
      Exit For
    End If
Continue:
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Yes, thanks. I can add what I need now that I have the base. A lot of times I can figure stuff out myself sometimes I just cant get it to work.
Thank you for your help.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

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