Repeat value certain number of times

broion

New Member
Joined
Jun 1, 2017
Messages
11
Hi Guys!

I'm having a hard time creating a formula to extract data based from this.

This is what's showing in one of the sheets:

8:30 PM 4.00
8:45 PM
9:00 PM 2.00

I would want to paste that on the next sheet which should look like this:

Mon
Shift Time
Emp 1 8:30 PM
Emp 2 8:30 PM
Emp 3 8:30 PM
Emp 4 8:30 PM
Emp 5 9:00 PM
Emp 6 9:00 PM

Basically, the next sheet will paste the time on column 2 four times if the first sheet's column 2 will have a value >0


 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Assuming your output is going to Sheet2, run this macro with your data sheet active...
Code:
[table="width: 500"]
[tr]
	[td]Sub ExpandEmployeeShiftTimeTable()
  Dim R As Long, Cnt As Long, X As Long, Data As Variant, Result As Variant
  Data = Range("A1:B" & Cells(Rows.Count, "A").End(xlUp).Row)
  ReDim Result(1 To Application.Sum(Columns("B")), 1 To 2)
  For R = 1 To UBound(Data)
    If Data(R, 2) > 1 Then
      For Cnt = 1 To Data(R, 2)
        X = X + 1
        Result(X, 1) = "Emp " & X
        Result(X, 2) = Format$(Data(R, 1), "h:mm AM/PM")
      Next
    End If
  Next
  Sheets("Sheet2").Range("A1:B2") = [{"Mon","";"Shift","Time"}]
  Sheets("Sheet2").Range("A3").Resize(UBound(Result, 1), UBound(Result, 2)) = Result
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Wow! That was great! Works good for me. However, my problem now is that this is a big spreadsheet. Sheet 1 actually contains 3 tables that I want to paste on the 2nd sheet. I can't post screenshot as I am at work and no admin rights to install the external apps recommended in your signature.

Is it possible to use a formula for this, or Macro is needed?

First table shows the shift time, 2nd table shows the lunch break for 1 hour then last table shows the 15-min break scheds.

Then the table has a 15-min interval from 12:00 AM to 11:45 PM

Sorry if this is a bit unclear.
 
Upvote 0
Wow! That was great! Works good for me. However, my problem now is that this is a big spreadsheet. Sheet 1 actually contains 3 tables that I want to paste on the 2nd sheet. I can't post screenshot as I am at work and no admin rights to install the external apps recommended in your signature.

Is it possible to use a formula for this, or Macro is needed?

First table shows the shift time, 2nd table shows the lunch break for 1 hour then last table shows the 15-min break scheds.

Then the table has a 15-min interval from 12:00 AM to 11:45 PM

Sorry if this is a bit unclear.

Completely unclear... at least to me. I think you will have to show us the before tables... or at least describe them in enough detail for us to be able to duplicate examples of them for ourselves... and then show us what you wanted the output to look like. By the way, as an aside, simplifying a problem for us will almost always get you a solution that you cannot use nor adapt for your actual situation.
 
Last edited:
Upvote 0
Hi Rick! Will just wait till I get home to post the screenshots as I don't have admin rights to install external apps here at work,
 
Upvote 0
I'm back!

So, I'm working on this excel file. This is the first sheet where I am calculating staffing based on forecasted volume:

Excel Workbook
BCDEFGHIJKLMNOP
2**Staffed for the day***Lunch break
3Intervals*MonTueWedThuFri*Intervals*MonTueWedThuFri
48:00 PM*******8:00 PM******
58:15 PM*******8:15 PM******
68:30 PM4.004.004.004.004.00**8:30 PM******
78:45 PM*******8:45 PM******
89:00 PM2.002.002.002.002.00**9:00 PM******
99:15 PM*******9:15 PM******
109:30 PM3.003.003.003.003.00**9:30 PM******
119:45 PM*******9:45 PM******
1210:00 PM*******10:00 PM******
1310:15 PM*******10:15 PM******
1410:30 PM*******10:30 PM******
1510:45 PM*******10:45 PM******
1611:00 PM2.002.002.002.002.00**11:00 PM******
1711:15 PM*******11:15 PM******
1811:30 PM*******11:30 PM******
1911:45 PM*******11:45 PM******
2012:00 AM*******12:00 AM3.003.003.003.003.00*
Staffing


And paste the analyzed schedules on the next sheet:

Excel Workbook
ABCDE
1*Mon
2Shift TimeBrk 1LunchBrk 2
3Emp 18:30 PM*12:00 AM*
4Emp 28:30 PM*12:00 AM*
5Emp 38:30 PM*12:00 AM*
6Emp 48:30 PM***
7Emp 59:00 PM***
8Emp 69:00 PM***
9Emp 79:30 PM***
10Emp 89:30 PM***
11Emp 99:30 PM***
12Emp 1011:00 PM***
13Emp 1111:00 PM***
schedule


Basically, I would want the second sheet to show the schedules based from the first sheet whereas the first sheet showed 4 employees scheduled at 08:30 PM, so on and so forth. Is this possible to be done via formula? Or do I have to enter VB code/macro for this to work? Hope this clears it up. Thanks in advance.
 
Upvote 0
Try......

1] Assume your sheet1 named "Staffing", sheet2 named "schedule"


2] In "schedule sheet" Shift Time column B3, formula copy down until blank :


=IFERROR(INDEX(Staffing!B$4:B$20,MATCH(1,INDEX(--(COUNTIF(B$2:B2,Staffing!B$4:B$20)< Staffing!C$4:C$20),0),0)),"")


3] In "schedule sheet" Lunch column D3, formula copy down until blank :


=IFERROR(INDEX(Staffing!J$4:J$20,MATCH(1,INDEX(--(COUNTIF(D$2:D2,Staffing!J$4:J$20)< Staffing!K$4:K$20),0),0)),"")


Regards
Bosco
 
Last edited:
Upvote 0
Hi All,

I have another problem in factoring the break schedules. My worksheet only has 1 table for both 1st and second breaks. Say, I only have 4 employees scheduled for the day. With the formula provided by Bosco, I am unable to identify the second break. Any workaround on this?

Excel Workbook
ABCDEF
1*15-min break
2IntervalsMonTueWedThuFri
3Time
410:30 PM1.00***1.00
510:45 PM1.00*1.00*1.00
611:00 PM1.001.001.001.001.00
711:15 PM1.001.001.001.001.00
811:30 PM*1.001.001.00*
911:45 PM*1.00*1.00*
1012:00 AM*****
1112:15 AM****1.00
1212:30 AM****1.00
1312:45 AM1.00*1.00*1.00
141:00 AM1.00*1.00*1.00
151:15 AM1.001.001.00**
161:30 AM1.001.001.001.00*
171:45 AM*1.00*1.00*
182:00 AM*1.00*1.00*
192:15 AM***1.00*
Sheet1


This is where the formula should auto populate here

Excel Workbook
ABCDE
1*Mon
2Shift TimeBrk 1LunchBrk 2
3Emp 1****
4Emp 2****
5Emp 3****
6Emp 4****
Sheet2
 
Upvote 0

Forum statistics

Threads
1,215,597
Messages
6,125,741
Members
449,256
Latest member
Gavlaar

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