Macro help to find a way to locate data

jwilson7981

New Member
Joined
Dec 11, 2018
Messages
1
I simply need to write a macro and I am very new to this part of it. I'm wanting to be able to locate a name on worksheet 1. Then using that data I need to find and search how many times that person has asked off in another workbook and return that to a cell in worksheet 1. These are 2 different workbooks. ie. I have a list of all my employees in the .xlsm file. I want it to be able to use their names and search a large workbook where I track all my schedules to see how many times they have asked off by locating their name and on that row finding how many times they have the work "OFF". So I will need to search that entire workbook. Can this be done. I can't find any where to do this.
I have the two files I'm working with. I have it where it will find the name I'm looking for but nothing else. And I would like to do this with the entire list of names without having to write an individual Sub for each name. I will paste the current code below.

Code:
Private Sub Find_Data()
    Dim counter As Integer
    Dim currentSheet As Integer
    Dim notFound As Boolean
    Dim yesNo As String
    notFound = True
    On Error Resume Next
    currentSheet = ActiveSheet.Index
    'datatoFind = InputBox("Please enter the value to search for")
    datatoFind2 = "OFF"
    datatoFind = Sheets("Request Off").Range("A3").Value
    If datatoFind = "" Then Exit Sub
    Workbooks("Schedule.xlsx").Activate
    sheetCount = ActiveWorkbook.Sheets.Count
    If IsError(CDbl(datatoFind)) = False Then datatoFind = CDbl(datatoFind)
    For counter = 1 To sheetCount
        Sheets(counter).Activate
        Cells.Find(What:=datatoFind, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
        
        Cells.Find(What:=datatoFind2, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
        
        If datatoFind2 = True Then
        
        
        
        
        
        
        
       ' If InStr(1, ActiveCell.Value, datatoFind) Then
        '    If HasMoreValues(counter + 1) Then 'Not completing the method and directly entering
         '       yesNo = MsgBox("Do you want to continue search?", vbYesNo)
        '        If yesNo = vbNo Then
          '          notFound = False
          '          Exit For
          '      End If
          '  End If
            Sheets(counter).Activate
      '  End If
    Next counter
    If notFound Then
        MsgBox ("Value not found")
        Sheets(currentSheet).Activate
    End If
End Sub
'Private Function HasMoreValues(ByVal sheetCounter As Integer) As Boolean
 '   HasMoreValues = False
  '  Dim str As String
   ' For counter = sheetCounter To sheetCount
    '    Sheets(counter).Activate
     '   str = Cells.Find(What:=datatoFind, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
      '  :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
       ' False, SearchFormat:=False).Value 'Not going further than this i.e. following code is not executed
        'If InStr(1, str, datatoFind) Then
         '   HasMoreValues = True
          '  Exit For
        'End If
    'Next counter
'End Function
 
Last edited by a moderator:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,214,780
Messages
6,121,527
Members
449,037
Latest member
tmmotairi

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