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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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.

Ref:AREAWeek 48Week 49Week 50Week 51Week 52Week 1Week 2Week 3
Sifters
PPMNPT1Silo 1XX
PPMNPT2Silo 2XX
PPMNPT3Silo 3XX
PPMNPT4Silo 4XX
Flour Transfer
PPMNPT6Rotary Sifter 1XX
PPMNPT7Rotary Sifter 2XX
PPMNPT8Rotary Sifter 3XX
PPMNPT9Rotary Sifter 4XX
Mixing Area

<tbody>
</tbody>

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,218,125
Messages
6,140,631
Members
450,300
Latest member
nashetho

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