Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hi, The code below needs to be used on seven worksheets (Mon - Sun). How can I resuse this code for each day of the week? I thought I could just set the wksdump to Tuesday etc. I also need to change the column I select in the array for each day (+1 column) - this is the last few lines of code where 7 will need to become 8 for Tuesday, 9 for Wednesday etc. I have only included here the code which needs to be reused. Dim i As Integer Dim j As Integer Set wksDump = ThisWorkbook.Sheets("Staff Monday") wksDump.Cells.ClearContents 'input header column wksDump.Cells(1, 1).Value = "Name" wksDump.Cells(1, 2).Value = "Status" wksDump.Cells(1, 3).Value = "Start" wksDump.Cells(1, 4).Value = "End" wksDump.Cells(1, 5).Value = "Shift" wksDump.Cells(1, 6).Value = "Description" wksDump.Cells(1, 7).Value = "06:00" 'input times in header column For i = 7 To 114 wksDump.Cells(1, i).Value = TimeofDay TimeofDay = TimeofDay + 0.006944444444 Next i 'input times in header column (past midnight) For i = 115 To 150 wksDump.Cells(1, i).Value = Midnight Midnight = Midnight + 0.006944444444 Next i For i = 2 To LastRow For j = 1 To 1 'j = columns wksDump.Cells(i, j) = AWD_Array(i, 2) Next j Next i For i = 2 To LastRow For j = 2 To 2 wksDump.Cells(i, j) = AWD_Array(i, 7) Next j Next i Thanks, Matt |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Call DayUpdate("Monday", 7)
Call DayUpdate("Tuesday", 8) 'etc. Public Sub DayUpdate(DayName As String, DayIndex As Long) Dim i As Integer Dim j As Integer Set wksDump = ThisWorkbook.Sheets("Staff " & DayName) wksDump.Cells.ClearContents 'input header column wksDump.Cells(1, 1).Value = "Name" wksDump.Cells(1, 2).Value = "Status" wksDump.Cells(1, 3).Value = "Start" wksDump.Cells(1, 4).Value = "End" wksDump.Cells(1, 5).Value = "Shift" wksDump.Cells(1, 6).Value = "Description" wksDump.Cells(1, 7).Value = "06:00" 'input times in header column For i = 7 To 114 wksDump.Cells(1, i).Value = TimeofDay TimeofDay = TimeofDay + 0.006944444444 Next i 'input times in header column (past midnight) For i = 115 To 150 wksDump.Cells(1, i).Value = Midnight Midnight = Midnight + 0.006944444444 Next i For i = 2 To LastRow For j = 1 To 1 'j = columns wksDump.Cells(i, j) = AWD_Array(i, 2) Next j Next i For i = 2 To LastRow For j = 2 To 2 wksDump.Cells(i, j) = AWD_Array(i, DayIndex) Next j Next i End Sub -- __________________________________ HTH Bob "MJKelly" wrote in message ... Hi, The code below needs to be used on seven worksheets (Mon - Sun). How can I resuse this code for each day of the week? I thought I could just set the wksdump to Tuesday etc. I also need to change the column I select in the array for each day (+1 column) - this is the last few lines of code where 7 will need to become 8 for Tuesday, 9 for Wednesday etc. I have only included here the code which needs to be reused. Dim i As Integer Dim j As Integer Set wksDump = ThisWorkbook.Sheets("Staff Monday") wksDump.Cells.ClearContents 'input header column wksDump.Cells(1, 1).Value = "Name" wksDump.Cells(1, 2).Value = "Status" wksDump.Cells(1, 3).Value = "Start" wksDump.Cells(1, 4).Value = "End" wksDump.Cells(1, 5).Value = "Shift" wksDump.Cells(1, 6).Value = "Description" wksDump.Cells(1, 7).Value = "06:00" 'input times in header column For i = 7 To 114 wksDump.Cells(1, i).Value = TimeofDay TimeofDay = TimeofDay + 0.006944444444 Next i 'input times in header column (past midnight) For i = 115 To 150 wksDump.Cells(1, i).Value = Midnight Midnight = Midnight + 0.006944444444 Next i For i = 2 To LastRow For j = 1 To 1 'j = columns wksDump.Cells(i, j) = AWD_Array(i, 2) Next j Next i For i = 2 To LastRow For j = 2 To 2 wksDump.Cells(i, j) = AWD_Array(i, 7) Next j Next i Thanks, Matt |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Bob,
I've used this method in the past. I thought I could loop through the worksheets, but if this is the more efficicent method then thanks, I was on the right path before! kind regards, Matt |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I suppose that you could use
For i = 1 to 7 Call DayUpdate(Format(i + 1, "dddd"), i+6) Next i but a loop is always less efficient, evn tough it may be slight. -- __________________________________ HTH Bob "MJKelly" wrote in message ... Thanks Bob, I've used this method in the past. I thought I could loop through the worksheets, but if this is the more efficicent method then thanks, I was on the right path before! kind regards, Matt |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Reusing Form Code | Excel Programming | |||
Reusing formula | Excel Discussion (Misc queries) | |||
Reusing grouping of non-adjacent cells | Excel Discussion (Misc queries) | |||
reusing a recordset for a pivot-table? | Excel Programming | |||
reusing a recordset for a pivot-table | Excel Programming |