Lookup set value, with multiple results.

robbo0224

New Member
Joined
Sep 17, 2014
Messages
23
Hi all,

I need help with a project i'm working on.
I have a sheet where I need to find and print worksheets based on weather that PPM is needed to be completed that month.
So for example, to Print all ppm's to be completed in week 6. I'd enter week 6 in the box and it looks up this week number in a row, then finds all occurrences of the number '1' in the column (there will be multiple) then look left to find the hyperlink to the sheet and print.

I need help with the lookup and looping it to find every entry.
Any help would be awesome. I'd attach the workbook, but i don't know how :-(
 

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.
The filter will only show the ones that need printing, i'm writing code that will print them automatically from a button click. So being able to use code to find the matches will tie in nicely. There are over 50 separate sheets, so printing manually takes a long time.
 
Upvote 0
Here's a piece of the table, and some code I've come up with so far.
The idea is that the user would enter the week number in the input box, then look up the week (below example Week 1) find the 'X' showing that PPM is needs to be printed. Then use's the hyperlink in the Area column to go to that sheet, print and more on to next entry.

[TABLE="class: grid, width: 966"]
<tbody>[TR]
[TD]Ref:[/TD]
[TD]AREA[/TD]
[TD]Week 48[/TD]
[TD]Week 49[/TD]
[TD]Week 50[/TD]
[TD]Week 51[/TD]
[TD]Week 52[/TD]
[TD]Week 1[/TD]
[TD]Week 2[/TD]
[TD]Week 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Sifters[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PPMNPT1[/TD]
[TD]Silo 1[/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PPMNPT2[/TD]
[TD]Silo 2[/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PPMNPT3[/TD]
[TD]Silo 3[/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PPMNPT4[/TD]
[TD]Silo 4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Flour Transfer[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PPMNPT6[/TD]
[TD]Rotary Sifter 1[/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PPMNPT7[/TD]
[TD]Rotary Sifter 2[/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PPMNPT8[/TD]
[TD]Rotary Sifter 3[/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PPMNPT9[/TD]
[TD]Rotary Sifter 4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Mixing Area[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Code:
Sub test1()    Dim PPMSchd As Range
    Dim Rng As Range
    Dim Lookup As String
    Dim Week As Integer
    
    Set PPMSchd = Sheets("Schedule").Range("A4:AC123")
    
    Week = InputBox("Please enter Week number:")
    Lookup = "Week " & Week
    
    Set Rng = PPMSchd.Find(Lookup)
    If Rng Is Nothing Then
        Msgbox Lookup & """ wasn't found.", vbInformation, "Invalid search"
    Else
        Rng.Find ("X")
        
        
    
End Sub

As you can see the code isn't finished as at this point i'm stuck.
 
Upvote 0
One way is to return the column of Week 1 via the Match function, loop through each row, wherever an X appears print the corresponding Area.
 
Upvote 0
Ok, the match function i can do but how do i loop though each row of that column? an find the area? would it be an embedded hlookup?
 
Upvote 0
Something like:

LastRow = Cells(Rows.Count, 1).End(xlUp).Row 'change 1 to whichever column is Area

for i = 3 to LastRow 'change 3 to the first row #

if cells(i,WeekColumn) = "X" then sheets(cells(i,1).value).printout 'change 1 to whichever column is Area
 
Upvote 0
Thank you, I've gotten a step closer but i can't end the 'for' statement. Here's my code so for;
Code:
Sub test1()    Dim PPMSchd As Range
    Dim Rng As Range
    Dim Lookup As String
    Dim Week As Integer
    
    Set PPMSchd = Sheets("Schedule").Range("A4:AC123")
    
    Week = InputBox("Please enter Week number:")
    Lookup = "Week " & Week
    WeekColumn = PPMSchd.Find(Lookup)
    LastRow = Cells(Rows.Count, 2).End(xlUp).Row
    For i = 6 To LastRow
    
    If Cells(i, WeekColumn) = "X" Then Sheets(Cells(i, 2).Hyperlinks(1).Follow).PrintOut
             
    Next
    Msgbox = ("Print Complete")
    
End Sub
 
Upvote 0
See if you can alter the ranges here to fit your data:


Excel 2010
ABCDEFGHIJ
1Ref:AREAWeek 48Week 49Week 50Week 51Week 52Week 1Week 2Week 3
2Sifters
3PPMNPT1Silo 1XX
4PPMNPT2Silo 2XX
5PPMNPT3Silo 3XX
6PPMNPT4Silo 4XX
7Flour Transfer
8PPMNPT6Rotary Sifter 1XX
9PPMNPT7Rotary Sifter 2XX
10PPMNPT8Rotary Sifter 3XX
11PPMNPT9Rotary Sifter 4XX
12Mixing Area
Sheet2


Code:
Sub printhyperlinks()
Dim Week%, Col%, LastRow%
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
Week = InputBox("Please enter Week number:")
Col = Application.Match("Week " & Week, Range("C1:J1"), 0) + 2
For i = 1 To LastRow
If Cells(i, Col).Value = "X" Then
Sheets(Cells(i, 2).Value).PrintOut
End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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