Search sheets for name in row then list column dates based on specific cell value

trev1234

New Member
Joined
Mar 13, 2021
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi, I hope someone can help with this or tell me if it is even possible, I have a workbook that logs holidays and has a sheet for each month eg January / February etc and laid out like below, I have a userform with a dropdown box with all the names, I would like to select a name from that list and press a button which searches through all the sheets January to December and finds the row that matches the name eg in the below say John (row 3) then find anything with a H in it and then return the date in row 1 and so on. so i would end up with a list of all the dates for john in a seperate sheet so in the example below i would end up with 03/01/21 and 06/01/21
Hope that makes sense and any help would be appreicated
Trev

1625077954225.png
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Something like this:

Where myName is from the userform

VBA Code:
Sub Summarise()

Dim sht As Worksheet
Dim sht2 As Worksheet
Dim rownum As Long
Dim colnum As Long
Dim myName As String

myName = "Steve"


Sheets.Add.Name =myName 
rownum2 = 1
Set sht2 = Sheets(myName)

For Each sht In ThisWorkbook.Worksheets
    If sht.Name <> myName Then
    rownum = 2
        Do Until sht.Cells(rownum, 1) = ""
        colnum = 2
            If sht.Cells(rownum, 1) = myName Then
                Do Until sht.Cells(1, colnum) = ""
                    If sht.Cells(rownum, colnum) = "H" Then
                        sht2.Cells(rownum2, 1) = sht.Cells(1, colnum)
                        rownum2 = rownum2 + 1
                    End If
                colnum = colnum + 1
                Loop
            End If
        rownum = rownum + 1
        Loop
    End If
Next sht

End Sub
 
Upvote 0
Solution
Something like this:

Where myName is from the userform

VBA Code:
Sub Summarise()

Dim sht As Worksheet
Dim sht2 As Worksheet
Dim rownum As Long
Dim colnum As Long
Dim myName As String

myName = "Steve"


Sheets.Add.Name =myName
rownum2 = 1
Set sht2 = Sheets(myName)

For Each sht In ThisWorkbook.Worksheets
    If sht.Name <> myName Then
    rownum = 2
        Do Until sht.Cells(rownum, 1) = ""
        colnum = 2
            If sht.Cells(rownum, 1) = myName Then
                Do Until sht.Cells(1, colnum) = ""
                    If sht.Cells(rownum, colnum) = "H" Then
                        sht2.Cells(rownum2, 1) = sht.Cells(1, colnum)
                        rownum2 = rownum2 + 1
                    End If
                colnum = colnum + 1
                Loop
            End If
        rownum = rownum + 1
        Loop
    End If
Next sht

End Sub
thank you mrshl9898 that is perfect :)
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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