VBA project to search, organize and return

brooksc29

Active Member
Joined
Jul 25, 2010
Messages
333
Hello all,

I am working on a project that is a bit over my head.

I have a workbook with daily information created on separate tabs (worksheets). Each worksheet is titled by date.

The format on each daily worksheet has rows under a headline "Facts", rows under a headline "Rumors" and rows under a headline "Highlights"

In each row, starting in column F, will be Date (column F)/ Team (G)/ Name (H) /Notes (L)/ Source (T) (there are some merged cells for formatting purposes).

The VBA will be needed to run a search program on a separate tab called PLAYER LOOKUP. I want the user to choose a name from a data validated drop down box (cell E3), and the VBA will take the name in that box, find and return all entered data by the chosen name and return the data under the appropriate headline of "Facts", "Rumors", or "Highlights" (it should be able to tell where the data is being pulled from).

Can anyone help me get started with this? (at least!!??)

Please let me know what I can provide to make this easier!

Thank you so much!
C
 
Last edited by a moderator:
Thanks Mumps!

There are a few bugs on the Player Lookup page. When a name is entered in the drop down box, the Highlights row section will jump up to cell R2. The Facts and Rumors tab does not do that.

Also, there is still an issue with clearing out previously entered names in the results if the user changes the name in the drop down box.

Finally, is there a way so that the data returned will be able be read in each cell? This was what I was worried about when reformatting Player Lookup. When the data is returned it is not easily read b/c of the size of the cell. Is there a way to format so that the text will wrap in the cell and the user can read it easily?
 
Upvote 0

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
Click here for the file. I could not reproduce the problem with clearing out previously entered names.
 
Upvote 0
Awesome! Thanks for the changes.

Last question (I hope!)... when I add in a new worksheet with the most recent date/update, the VBA has an error... it highlights
rumors = ws.Range("B:B").Find("RUMORS").Row
in the macro.

After I add a new worksheet, the macro clears the data and stops working.

Should I change anything in the macro?
 
Upvote 0
Mumps,

I'm still a little confused by this line in the macro

rumors = ws.Range("B:B").Find("RUMORS").Row

I had to add two sheets titled STATS19hit and STATS19pitch. These will have a macro to pull stats from the web.

After adding these sheets I got the error in the macro again highlighting the rumors line.

What is that line saying to do?


 
Upvote 0
The macro loops through the sheets and excludes any sheets that are not date sheets. If you add more non date sheets the macro has to exclude them. Will you be adding any more sheets?
 
Upvote 0
I added three sheets that are labeled STATS... with various endings based on what stats they are.

Other than future date sheets, no other sheets should be added moving forward.

I'll share my work with you here so you can see the recent changes.
 
Upvote 0
Try:
Code:
Private Sub ComboBox1_Change()
    Application.ScreenUpdating = False
    Dim LastRow As Long, LastRow2 As Long, player As Range, rumors As Long, high As Long, ws As Worksheet
    With Range("D13:T1000")
        .ClearContents
        .Borders.LineStyle = xlNone
    End With
    For Each ws In Sheets
        If InStr(1, ws.Name, "-") Then
            LastRow = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            rumors = ws.Range("B:B").Find("RUMORS").Row
            high = ws.Range("B:B").Find("HIGHLIGHTS").Row
            Set player = ws.Range("E6:E" & rumors - 1).Find(ComboBox1.Value, LookIn:=xlValues, lookat:=xlPart)
            If Not player Is Nothing Then
                Intersect(ws.Rows(player.Row), ws.Range("B:B,D:D,E:E,F:F,G:G")).Copy Cells(Rows.Count, "D").End(xlUp).Offset(1, 0)
                LastRow2 = Range("D" & Rows.Count).End(xlUp).Row
                Rows("13:" & LastRow2).AutoFit
                Sheets("PLAYER LOOKUP").Sort.SortFields.Clear
                Sheets("PLAYER LOOKUP").Sort.SortFields.Add Key:=Range( _
                    "D13:D" & LastRow2), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
                    xlSortNormal
                With Sheets("PLAYER LOOKUP").Sort
                    .SetRange Range("D12:H" & LastRow2)
                    .Header = xlYes
                    .MatchCase = False
                    .Orientation = xlTopToBottom
                    .SortMethod = xlPinYin
                    .Apply
                End With
            End If
            Set player = ws.Range("E" & rumors + 2 & ":E" & high - 1).Find(ComboBox1.Value, LookIn:=xlValues, lookat:=xlPart)
            If Not player Is Nothing Then
                Intersect(ws.Rows(player.Row), ws.Range("B:B,D:D,E:E,F:F,G:G")).Copy Cells(Rows.Count, "J").End(xlUp).Offset(1, 0)
                LastRow2 = Range("J" & Rows.Count).End(xlUp).Row
                Rows("13:" & LastRow2).AutoFit
                Sheets("PLAYER LOOKUP").Sort.SortFields.Clear
                Sheets("PLAYER LOOKUP").Sort.SortFields.Add Key:=Range( _
                    "J13:J" & LastRow2), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
                    xlSortNormal
                With Sheets("PLAYER LOOKUP").Sort
                    .SetRange Range("J12:N" & LastRow2)
                    .Header = xlYes
                    .MatchCase = False
                    .Orientation = xlTopToBottom
                    .SortMethod = xlPinYin
                    .Apply
                End With
            End If
            Set player = ws.Range("E" & high + 2 & ":E" & LastRow).Find(ComboBox1.Value, LookIn:=xlValues, lookat:=xlPart)
            If Not player Is Nothing Then
                Intersect(ws.Rows(player.Row), ws.Range("B:B,D:D,E:E,F:F,G:G")).Copy Cells(Rows.Count, "P").End(xlUp).Offset(1, 0)
                LastRow2 = Range("P" & Rows.Count).End(xlUp).Row
                Rows("13:" & LastRow2).AutoFit
                Sheets("PLAYER LOOKUP").Sort.SortFields.Clear
                Sheets("PLAYER LOOKUP").Sort.SortFields.Add Key:=Range( _
                    "P13:P" & LastRow2), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
                    xlSortNormal
                With Sheets("PLAYER LOOKUP").Sort
                    .SetRange Range("P12:T" & LastRow2)
                    .Header = xlYes
                    .MatchCase = False
                    .Orientation = xlTopToBottom
                    .SortMethod = xlPinYin
                    .Apply
                End With
            End If
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
This macro checks if the sheet name contains the character "-" (hyphen). This will limit the search to the "Date" sheets only. If you add any more sheets, make sure the sheet name doesn't contain a hyphen.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
Latest member
laura12345

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