Creating A List When a Value Falls Within A Range

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am here hoping someone can help me with coding this particular task.

I have a service time, as a decimal, assigned to variable 't_min'. In my example , t_min = 0.72 (5:15 PM)

I have a staff schedule in workbook("wb"), worksheet("STAFF"). This object is assigned to variable ws_corestaff.


Excel 2010
ABCDE
3Staff Roster
4CUE11Kelly0.2916670.625
5CUE2XNot Staffed0.2916670.625
6CUL12Jen0.6666671
7HPE1AMorgan0.2916670.625
8HPE2XNot Staffed0.2916670.625
9HPL1CTessa0.56250.895833
10HPL2XNot Staffed
11RPE1ACorey0.2916670.625
12RPE2AJessica0.2916670.625
13RPL1CAshley B.0.56250.895833
14RPL2XNot Staffed
15WPE1AKiana0.2916670.625
16WPE2CJeremy0.2916670.625
17WPL1CLauren0.56250.895833
18WPL2XNot Staffed
STAFF


What I would like to do, is generate a list of values (crews) from column A in which the service time (t_min) falls within that crews shift (Start-Column D - End-Column E)

The list can start at H3 on worksheet ws_ws_core.

I will be be very appreciative of any help provided.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I've done this on a single sheet, but if it is what you want, hopefully you can adapt it.

Rich (BB code):
Sub Roster()
  Dim t_min As Single
  Dim a As Variant, b As Variant
  Dim i As Long, k As Long
  
  t_min = 0.72
  a = Range("A2:E" & Range("A" & Rows.Count).End(xlUp).Row).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    If t_min >= a(i, 4) And t_min <= a(i, 5) Then
      k = k + 1
      b(k, 1) = a(i, 1)
    End If
  Next i
  Range("H3").Resize(k).Value = b
End Sub

Original data in A:E, code results in col H

Excel Workbook
ABCDEFGH
1Staff Roster
2CUE11Kelly0.2916670.625
3CUE2XNot Staffed0.2916670.625CUL1
4CUL12Jen0.6666671HPL1
5HPE1AMorgan0.2916670.625RPL1
6HPE2XNot Staffed0.2916670.625WPL1
7HPL1CTessa0.56250.895833
8HPL2XNot Staffed
9RPE1ACorey0.2916670.625
10RPE2AJessica0.2916670.625
11RPL1CAshley B.0.56250.895833
12RPL2XNot Staffed
13WPE1AKiana0.2916670.625
14WPE2CJeremy0.2916670.625
15WPL1CLauren0.56250.895833
16WPL2XNot Staffed
Roster
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,431
Members
448,961
Latest member
nzskater

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