All,
I am trying to pass a range (single cell) from a master subroutine into another subroutine that is called. That "child" subroutine is going to act off the passed range (single cell) using the ActiveCell.Offset() command. A few questions:
Master Sub:
- I want to make the child subroutine be executed on each cell in a row of cells. For example, for a range(B10:H10), I'd like to call the subroutine for each cell. What is the syntax or command I use in the master subroutine?
- What syntax do I put in paranthesis in the master subroutine to pass the correct range cell?:
- In the child subroutine, how do I take whatever is in the subroutine name() paranthesis and correctly name it into a variable or whatever so that the offset command is used appropriately? In the child subroutine code below, the second line of Range.Select is just there while I manually execute the child subroutine.
- Is there another option besides "ActiveCell" to use so that the user doesn't have to watch excel select each cell as it executes the child subroutine.
Here is the child subroutine below. Any help greatly appreciate figuring out the best syntax to use. I'd like to get rid of Activecell so excel doesn't highlight each cell as the code is executed.
I am trying to pass a range (single cell) from a master subroutine into another subroutine that is called. That "child" subroutine is going to act off the passed range (single cell) using the ActiveCell.Offset() command. A few questions:
Master Sub:
Code:
Sub master()
Call ActualTimeTest()
End Sub
- I want to make the child subroutine be executed on each cell in a row of cells. For example, for a range(B10:H10), I'd like to call the subroutine for each cell. What is the syntax or command I use in the master subroutine?
- What syntax do I put in paranthesis in the master subroutine to pass the correct range cell?:
- In the child subroutine, how do I take whatever is in the subroutine name() paranthesis and correctly name it into a variable or whatever so that the offset command is used appropriately? In the child subroutine code below, the second line of Range.Select is just there while I manually execute the child subroutine.
- Is there another option besides "ActiveCell" to use so that the user doesn't have to watch excel select each cell as it executes the child subroutine.
Here is the child subroutine below. Any help greatly appreciate figuring out the best syntax to use. I'd like to get rid of Activecell so excel doesn't highlight each cell as the code is executed.
Code:
Sub ActualTimeTest()
Range("I15").Select
Select Case ActiveCell.Value
Case "": Exit Sub 'If Scheduled Value is blank, quit routine
Case Else 'If there is a Scheduled Event
Select Case ActiveCell.Offset(2, 0).Value 'Look if an Actual Value is inputted
Case "": 'If There is no Actual Value yet
If ActiveCell - Range("A9") > 0.25 / 24 Then 'If Scheduled Time is Greater than 00:15 after Now
ActiveCell.Offset(2, -1) = "Now 15 min before Scheduled"
With ActiveCell.Offset(1, 0).Interior 'Make Cell fill color clear
.ColorIndex = 2
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Exit Sub
ElseIf ActiveCell - Range("A9") <= 0.25 / 24 And ActiveCell - Range("A9") >= 0 Then 'If Scheduled Time is Less than 00:15 After Now
ActiveCell.Offset(2, -1) = "Now 15 min within Scheduled"
With ActiveCell.Offset(1, 0).Interior 'Make Cell fill color yellow
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
ElseIf ActiveCell - Range("A9") < 0 Then 'If Scheduled Time is before Now Time, i.e. if Now has passed scheduled time
ActiveCell.Offset(2, -1) = "Now has passed scheduled time"
With ActiveCell.Offset(1, 0).Interior 'Make Cell fill color red
.ColorIndex = 3
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
Case Is <> "" 'If Actual is not Blank and there is a value in the Actual cell
If ActiveCell + 0.25 / 24 - ActiveCell.Offset(2, 0) >= 0 Then 'If the Actual Time is before Scheduled time +/- 00:15
ActiveCell.Offset(2, -1) = "Actual time is on time and complete"
With ActiveCell.Offset(1, 0).Interior 'Make Cell fill color green
.ColorIndex = 4
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
ElseIf ActiveCell + 0.25 / 24 - ActiveCell.Offset(2, 0) < 0 Then 'If the Actual Time is late and executed at least 00:15 past Scheduled Time
ActiveCell.Offset(2, -1) = "Actual time is late, past Scheduled + 00:15"
With ActiveCell.Offset(1, 0).Interior 'Make Cell fill color red
.ColorIndex = 3
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End Select
End Select
End Sub