Index Match or HLOOKUP or Array

cccbzg

Board Regular
Joined
Oct 5, 2014
Messages
68
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to write a macro to gather data from inbox, look through a series of columns to see if the the inbox data is listed (top row) and on a hit, access each row below, one by one to do some calculations. I'm not sure how to approach this. So for example, I want to key in Monday, find the Monday column, and go through the 5 rows to get the numbers 3, then 2, then 6, then 4, then 5. Does that make sense? Also, the # of columns and rows would be variable and data can be changed on the fly. Any help would be very much appreciated. Many thanks!!

[TABLE="width: 281"]
<colgroup><col><col><col><col><col></colgroup><tbody>[TR]
[TD]Monday[/TD]
[TD]Tuesday [/TD]
[TD]Wednesday[/TD]
[TD]Friday[/TD]
[TD]Saturday[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]6[/TD]
[TD]3[/TD]
[TD]2[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]4[/TD]
[TD]4
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]8[/TD]
[TD]7[/TD]
[TD]6[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]9[/TD]
[TD]9[/TD]
[TD]8[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]12[/TD]
[TD]11[/TD]
[TD]10[/TD]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 888"]
<colgroup><col><col><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: right"]Bonnie
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]7[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
SO when the user types Monday they get the data returned like this?

[TABLE="width: 357"]
<tbody>[TR]
[TD="class: xl65, width: 59"]Monday[/TD]
[TD="class: xl65, width: 47, align: right"]3[/TD]
[TD="class: xl65, width: 59, align: right"]2[/TD]
[TD="class: xl65, width: 64, align: right"]6[/TD]
[TD="class: xl65, width: 64, align: right"]4[/TD]
[TD="class: xl65, width: 64, align: right"]5[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Excel 2012
ABCDEFGHIJKL
1MondayTuesdayWednesdayFridaySaturdaySelect From:12345
236323Monday32645
324544
468765
549986
651211107
Sheet1
Cell Formulas
RangeFormula
H2=INDEX($A$2:$E$6,H$1,MATCH($G2,DaysWeek,0))
Named Ranges
NameRefers ToCells
DaysWeek=Sheet1!$A$1:$E$1



In Cell G2 I use Data Validation (Creating a Dropdown of Monday thru Saturday) using List refers to: = DaysWeek
Copy Cell H2 to I2:L2
 
Upvote 0
Thanks so much. Although I don't think I described this well, I think you have put me on the right track, Jim.

This is actually part of a large macro which does a bunch of things...long story. What I should have explained is that I would like the user to key the day of the week in an inputbox when prompted. The macro should then validate the day from row 1 and then look up the values in col1. When there is a hit on the day, display a message "Monday found" and then cycle through each remaining row displaying to the user in a message box, each value one at a time, until the end of the column. So the user would key "Monday" - receive "Monday found" then the user would get a message box saying 3, then a box displaying 2, then one displaying 6, one displaying 4, then 5. if there was NO HIT on the day entered, display "not found" end exit the routine.

Thanks to all.
 
Upvote 0
With your worksheet displaying ONLY the A1:E6 range info as before, run this macro.. (on a copy of your file, first)

Code:
Sub Foo()
Dim MyDay As String
Dim MyCol As Long, i As Long
MyDay = Application.InputBox("Enter Day of Week")
If WorksheetFunction.CountIf(Range("A1:E1"), MyDay) Then
MsgBox MyDay & " Found"
Else
MsgBox MyDay & " Not Found"
Exit Sub
End If
MyCol = WorksheetFunction.Match(MyDay, Range("A1:E1"), 0)
For i = 2 To 6
MsgBox Cells(i, MyCol).Value
Next i
End Sub
 
Upvote 0
That works just great. Thanks so very much! I do have one additional need. Since the # of columns and rows would be variable I would need to account for that possibility. Again, my thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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