PDA

View Full Version : If statement checking last digit and modifying time



kingsdime29x
04-14-2016, 08:41 PM
Hello,

I am working on a way to look for the last digit in column B of my spreadsheet which is the game indicator (0, 1, 2) and take that number and convert it to a time that is within column A.

I have attached my workbook. For example, in column B, if the last digit equals a zero, I would like to keep the time as 12:00 AM in column A. If the last digit is a 1 in column B, I would like for the time to change in column A to 6:00 AM. If the last digit is a 2 in column, I would like for the time in column A to change to 12:00pm.

Is there a way also to have this work across all worksheets within the workbook as well. Anyone who help me with creating a solution for this I would greatly appreciate it.

Bob Phillips
04-15-2016, 01:42 AM
Put this code in the Thisworkbook code module


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

On Error GoTo wsc_exit

Application.EnableEvents = False

If Target.Column = 2 Then

Select Case Right$(Target.Value, 1)

Case "0": Target.Offset(0, -1).Value = Int(Target.Offset(0, -1).Value)
Case "1": Target.Offset(0, -1).Value = Int(Target.Offset(0, -1).Value) + 1 / 4
Case "2": Target.Offset(0, -1).Value = Int(Target.Offset(0, -1).Value) + 1 / 2
End Select
End If

wsc_exit:
Application.EnableEvents = True
End Sub