VBA: Return Row number of a time range based on value in another cell

RobOttman

New Member
Joined
Feb 15, 2017
Messages
1
I have been searching all day for answers and have made zero progress. I hope that you can help me!

I have one worksheet ("Schedule") and in column L there is the StartTime for all of our classes. On another worksheet("Times") I have a list of the standard start times for class periods. What I want to do is have a VBA macro start at the top of column L in Schedules, then find the row number (or, if it's easier, return a value from a neighboring column, which would just be the row number anyway) for the time time range where the "active cell" of column L falls. I would then have VBA put this value in column M.

So "Times" looks like this:
8:15 AM
9:20 AM
10:25 AM
11:30 AM
12:35 PM
1:40 PM
2:45 PM
3:50 PM
4:00 PM
7:00 PM

<colgroup><col></colgroup><tbody>
</tbody>

Column L of "Schedule" contains times like 8:15 AM and 9:20 AM so that when I run the macro, column M would display "1" and "2" respectively (only 1 time per row! I'm not trying to get two periods out of one start time!). Similarly, if the start time is, say, 5:20 PM, the macro would return "9", since "5:20 PM" is between 4:00 PM and 7:00 PM.

I have tried using function, such as Match and VLookup, but those have not worked. I can't figure out how to use variables in VLookup, and for some reason Excel is unable to "MATCH" the times as exported from Access. (That is another problem entirely! If I export the query, the two times appear 100% identical, but will never match. If I copy the column from Access and paste it into Excel, they'll match as you would expect. I have no idea why...)

So any light you could shed on how to compare the value of one cell to a range of values in another worksheet via VBA would be greatly appreciated!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

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