sequence order with table

kelvin_9

Active Member
Joined
Mar 6, 2015
Messages
444
Office Version
  1. 2019
hi all, how are you today?
i have a question on sequence issue, i use my macro to run my employee schedule, however the result return lowest to highest in first column-name
if i request this column-name with my needs(like peter/susan/kelvin instead of kelvin/peter/susan), the macro can not run successfully with all employee. how can i fix this?
i hope you guys would understood my poor english what i am talking about. thanks everyone!

VBA Code:
Sub Macro001()
'
' Macro001 Macro
'

'
    
    Sheets("schedule").Select
    ActiveSheet.Cells.UnMerge
    
    Dim C As Integer
    C = ActiveSheet.Cells.SpecialCells(xlLastCell).Column
    Do Until C = 0
    If WorksheetFunction.CountA(Columns(C)) = 0 Then
    Columns(C).Delete
    End If
    C = C - 1
    Loop
    Range("A1").Select
    
    Application.Goto Reference:="R200C1"
    ActiveCell.FormulaR1C1 = "END"
    Range("A1:A200").Select
    Selection.SpecialCells(xlCellTypeConstants, 23).Select
    Selection.Copy
    Sheets("result").Select
    Range("A50").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("A1").Select
    Application.CutCopyMode = False
    Sheets("schedule").Select
    Range("A1").Select

End Sub
Sub Macro002()
'
' Macro002 Macro
'

'
    Sheets("result").Select
    Dim rDate As Range, rDest As Range
    Dim sText1 As String, sText2 As String

    Set rDate = Range("c50")
    Set rDest = Range("c51")

    sText1 = "TEXT(MIN(IFERROR(TIMEVALUE(LEFT(INDEX('schedule'!$C:$C,MATCH('result'!$A51,'schedule'!$A:$A,0)):INDEX('schedule'!$C:$C,MATCH('result'!$A52,'schedule'!$A:$A,0)-1),5)),1)),""hh:mm"")"
    sText2 = "TEXT(MAX(IFERROR(TIMEVALUE(MID(INDEX('schedule'!$C:$C,MATCH('result'!$A51,'schedule'!$A:$A,0)):INDEX('schedule'!$C:$C,MATCH('result'!$A52,'schedule'!$A:$A,0)-1),7,5)),0)),""hh:mm"")"

    rDest.FormulaArray = "=IF(INDEX('schedule'!$C:$C,MATCH('result'!$A51,'schedule'!$A:$A,0))="""","""",1111&"" - ""&2222)"
    rDest.Replace "1111", sText1, LookAt:=xlPart
    rDest.Replace "2222", sText2, LookAt:=xlPart

    Range("c51").AutoFill Destination:=Range("c51:c" & Range("a" & Rows.Count).End(xlUp).Row)

    Range("d51").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(RC[-1]=""00:00 - 00:00"",VLOOKUP(RC1,schedule!C1:C9,3,FALSE),"""")"
    Range("d51").AutoFill Destination:=Range("d51:d" & Range("a" & Rows.Count).End(xlUp).Row)
    
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,214,591
Messages
6,120,424
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