Consulting

Results 1 to 2 of 2

Thread: If statement checking last digit and modifying time

  1. #1

    If statement checking last digit and modifying time

    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.
    Attached Files Attached Files

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •