+ Reply to Thread
Results 1 to 14 of 14

Need help with time format and modifying existing code

  1. #1
    Registered User
    Join Date
    08-06-2018
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    8

    Need help with time format and modifying existing code

    Hello there, im using the following code so that I can enter time without colons

    Please Login or Register  to view this content.
    The problem im having is that this code will only allow me to enter hh:mm. I need to enter hh:mm:ss. How would I modify or add to the code to be able to also enter the seconds in my time?

    Im very new to this code thing so yeah im sure this will be a simple thing for some of you that have more advanced knowledge of excel.

    Thanks in advance
    Last edited by jeffreybrown; 03-18-2019 at 05:19 PM. Reason: Please use code tags!

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,471

    Re: Need help with time format and modifying existing code

    .
    This works here :

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-06-2018
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    8

    Re: Need help with time format and modifying existing code

    Thanks for the reply, this fixes the format issue but it now affects the whole worksheet. Is it possible to have it applied to only specific columns like my original one had?

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,471

    Re: Need help with time format and modifying existing code

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-06-2018
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    8

    Re: Need help with time format and modifying existing code

    Thank you that now applies only the columns I want. Normally when entering data you hit tab once and it automatically sets the data for that cell and moves over to the next cell, I noticed that with this code I now have to use tab on my keyboard twice to move to the next cell when entering data. This applies to the whole worksheet. Do you know what in the code is causing that?

  6. #6
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,471

    Re: Need help with time format and modifying existing code

    .
    Either DELETE or comment out "Target.Select" at the bottom of the macro.


    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-06-2018
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    8

    Re: Need help with time format and modifying existing code

    This is perfect, it works exactly the way I need it to, thank you for all your help.

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,471

    Re: Need help with time format and modifying existing code

    .
    You are welcome.

  9. #9
    Registered User
    Join Date
    08-06-2018
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    8

    Re: Need help with time format and modifying existing code

    I now have another question with this same code, today I wanted to use it in a different workbook where I need the code to run in 7 separate columns. I was able to successfully add a second column but it wont let me use it in more then 2 columns. What is restricting the code to only 2 columns?

  10. #10
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,471

    Re: Need help with time format and modifying existing code

    .
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    08-06-2018
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    8

    Re: Need help with time format and modifying existing code

    I figured it would be some simple thing, thanks again for helping me learn

  12. #12
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,471

    Re: Need help with time format and modifying existing code

    .
    You are welcome !

  13. #13
    Registered User
    Join Date
    08-06-2018
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    8

    Re: Need help with time format and modifying existing code

    I have the following code. What do I need to change in the tab array section so that I can start at any of the cells in the tab array line and it will go the the next listed cell? Right now I have to start at my first listed cell (B
    6) otherwise it just moves left to right across the work sheet as if there was n code.


    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B:B, E:E, H:H, K:K, N:N, Q:Q, T:T")) Is Nothing Then
    If Target.Count > 1 Then Exit Sub
    With Target
    On Error Resume Next
    If IsNumeric(.Value) Then
    If .Value >= 2 Or .Value = 1 Then
    Application.EnableEvents = False
    .Value = Format(.Value, "00\:00")
    .NumberFormat = "hh:mm"
    Application.EnableEvents = True
    End If
    End If
    On Error GoTo 0
    End With
    End If

    Dim tabArray As Variant
    Dim i As Long
    tabArray = Array("B6", "B7", "E6", "E7", "H6", "H7", "K6", "K7", "N6", "N7", "Q6", "Q7", "T6", "T7", "B11", "B12", "E11", "E12", "H11", "H12", "K11", "K12", "N11", "N12", "Q11", "Q12", "T11", "T12", "B16", "B17", "E16", "E17", "H16", "H17", "K16", "K17", "N16", "N17", "Q16", "Q17", "T16", "T17", "B21", "B22", "E21", "E22", "H21", "H22", "K21", "K22", "N21", "N22", "Q21", "Q22", "T21", "T22", "B26", "B27", "E26", "E27", "H26", "H27", "K26", "K27", "N26", "N27", "Q26", "Q27", "T26", "T27", "B31", "B32", "E31", "E32", "H31", "H32", "K31", "K32", "N31", "N32", "Q31", "Q32", "T31", "T32")
    Application.ScreenUpdating = False
    For i = LBound(tabArray) To UBound(tabArray)
    If tabArray(i) = Target.Address(0, 0) Then
    If i = UBound(tabArray) Then
    Me.Range(tabArray(LBound(tabArray))).Select
    Else
    Me.Range(tabArray(i + 1)).Select
    End If
    End If
    Next i
    Application.ScreenUpdating = True



    End Sub

  14. #14
    Registered User
    Join Date
    08-06-2018
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    8

    Re: Need help with time format and modifying existing code

    I realized I had made a change in my worksheet that caused the code to not work. It works exactly like I wanted it to now so its all good. Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Modifying Existing Code + Find Range Differences
    By jrean042 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-26-2019, 10:09 AM
  2. Modifying existing code to save worksheet
    By Woopwoop in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-26-2015, 08:54 PM
  3. Modifying existing code
    By rhouston08 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-13-2015, 06:03 PM
  4. Modifying an existing excel time formula
    By spittingfire in forum Excel General
    Replies: 0
    Last Post: 02-03-2015, 10:04 PM
  5. [SOLVED] Add two more columns, modifying an existing VBA code help.
    By Anka in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 02-17-2013, 01:24 PM
  6. Modifying existing VBA code to find different file name
    By PittsburghEng in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2010, 03:24 PM
  7. Help modifying existing VBA code
    By camcafe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2008, 11:02 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1