Hey guys,
I'm getting stuck trying to run this code as it continues to insist that I have a "Compile error: Expected Function or variable" at the highlighted region. I've tried googling a solution but have come up with nothing. All I want to do is take in a time from a certain cell, run it through a process, then output it to a range of cells. I'm getting an error just trying to select the worksheets, which is especially weird because I tried a fairly similar code at my home computer and it worked. Any help would be very much appreciated.
Gurpreet
Public Function GetShift()
Dim CurrentShiftStart As Date
Dim tempHour As Integer
Dim Linet(6) As Variant
Linet(0) = "B1"
Linet(1) = "PC1"
Linet(2) = "PC2"
Linet(3) = "PC3"
Linet(4) = "PC4"
Linet(5) = "PC5"
Linet(6) = "Graph Page"
Dim iCount As Integer
Dim Line As Worksheet
For iCount = 0 To 5
Set Line = ThisWorkbook.Worksheets(Linet(iCount))
Line.Select
tempHour = Format(ActiveSheet.Range("C10").Select, "hh")
If (tempHour = 23) Or (tempHour < 7) Then
CurrentShiftName = "Shift 1"
ElseIf (tempHour >= 7 And tempHour < 15) Then
CurrentShiftName = "Shift 2"
ElseIf (tempHour >= 15 And tempHour < 23) Then
CurrentShiftName = "Shift 3"
End If
Linet(6).Range("C8").Activate
Selection.Offset(iCount, 0).Select
ActiveCell.Value = CurrentShiftName
Next iCount
End Function
I'm getting stuck trying to run this code as it continues to insist that I have a "Compile error: Expected Function or variable" at the highlighted region. I've tried googling a solution but have come up with nothing. All I want to do is take in a time from a certain cell, run it through a process, then output it to a range of cells. I'm getting an error just trying to select the worksheets, which is especially weird because I tried a fairly similar code at my home computer and it worked. Any help would be very much appreciated.
Gurpreet
Public Function GetShift()
Dim CurrentShiftStart As Date
Dim tempHour As Integer
Dim Linet(6) As Variant
Linet(0) = "B1"
Linet(1) = "PC1"
Linet(2) = "PC2"
Linet(3) = "PC3"
Linet(4) = "PC4"
Linet(5) = "PC5"
Linet(6) = "Graph Page"
Dim iCount As Integer
Dim Line As Worksheet
For iCount = 0 To 5
Set Line = ThisWorkbook.Worksheets(Linet(iCount))
Line.Select
tempHour = Format(ActiveSheet.Range("C10").Select, "hh")
If (tempHour = 23) Or (tempHour < 7) Then
CurrentShiftName = "Shift 1"
ElseIf (tempHour >= 7 And tempHour < 15) Then
CurrentShiftName = "Shift 2"
ElseIf (tempHour >= 15 And tempHour < 23) Then
CurrentShiftName = "Shift 3"
End If
Linet(6).Range("C8").Activate
Selection.Offset(iCount, 0).Select
ActiveCell.Value = CurrentShiftName
Next iCount
End Function