Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,590
- Office Version
- 365
- 2016
- Platform
- Windows
I am having an issue with how my time value cell contents are being displayed in my workbook.
I have a source data range in worksheet ws_lists. The values in columns in AM and AN represent the decimal equivalents of hours.
Using this code, I am trying to populate cells R3 and T3 with the values of iShifts and iShifte (declared as integers) respectively. Cells R3 and T3 are formatted as h:mm AM/PM. When I run my code, I am getting a value of 12:00 AM in both cells. If I click on R3, the formula box shows 12:00:00 AM, an in T3 1900-01-01 12:00:00 AM
Anyone wish to point me in the right direction? I'm not sure where it's best to format numbers, at the source, or destination. For note, if lshift = 4, there will be no values for iShifts or iShifte. In that case, the user will be prompted to enter the times in cells R3 and T3, formatted as h:mm AM/PM.
I have a source data range in worksheet ws_lists. The values in columns in AM and AN represent the decimal equivalents of hours.
wloopkdata.xlsm | ||||||
---|---|---|---|---|---|---|
AK | AL | AM | AN | |||
2 | 1 | [1] 7:00A - 3:00P | 0.291667 | 0.625000 | ||
3 | 2 | [2] 3:00P - 11:00P | 0.625000 | 0.958333 | ||
4 | 3 | [3] 11:00P - 7:00A | 0.958333 | 0.291667 | ||
5 | 4 | [4] Other | ||||
LISTS |
Using this code, I am trying to populate cells R3 and T3 with the values of iShifts and iShifte (declared as integers) respectively. Cells R3 and T3 are formatted as h:mm AM/PM. When I run my code, I am getting a value of 12:00 AM in both cells. If I click on R3, the formula box shows 12:00:00 AM, an in T3 1900-01-01 12:00:00 AM
Code:
Private Sub Worksheet_change(ByVal Target As Range)
Dim sName As String
Dim leNum As Long
Dim lshift As Long
Dim sShift As String
Dim iShifts As Integer
Dim iShifte As Integer
If Not mbevents Then Exit Sub
If Target.Address = "$M$2" Then
mbevents = False
sName = Target.Value
MsgBox sName, , "NAME CHANGE"
Unprotect
With Range("M2").Font
.Color = RGB(19, 65, 98)
.Italic = False
End With
leNum = Application.WorksheetFunction.VLookup(sName, ws_lists.Range("A2:B50"), 2, False)
lshift = Application.WorksheetFunction.VLookup(sName, ws_lists.Range("A2:C50"), 3, False)
sShift = Application.WorksheetFunction.VLookup(lshift, ws_lists.Range("AK2:AN5"), 2, False)
iShifts = Application.WorksheetFunction.VLookup(lshift, ws_lists.Range("AK2:AN5"), 3, False)
iShifte = Application.WorksheetFunction.VLookup(lshift, ws_lists.Range("AK2:AN5"), 4, False)
Range("T2") = leNum
Range("M3") = sShift
Range("R3") = iShifts
Range("T3") = iShifte
mbevents = True
End If
End Sub
Anyone wish to point me in the right direction? I'm not sure where it's best to format numbers, at the source, or destination. For note, if lshift = 4, there will be no values for iShifts or iShifte. In that case, the user will be prompted to enter the times in cells R3 and T3, formatted as h:mm AM/PM.