+ Reply to Thread
Results 1 to 5 of 5

Amend code to work with time instead of date

  1. #1
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    758

    Amend code to work with time instead of date

    Hi all,

    I have the following code, which builds a table and imports the data from another tab:

    Please Login or Register  to view this content.
    Re the Date variable it currently works with Date in Column A of another Worksheet.

    Obviously for it to work with time I need to make changes around Dt to Tm, but I am unsure how to declare Time as a variable.

    The time will be a range, so in each cell it is displayed as 07:30 - 08:00, 08:00 - 08:30 etc etc.

    Any ideas?

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Amend code to work with time instead of date

    Hi there,

    Please Login or Register  to view this content.
    You can declare a time value as being of type Date. (That's what I usually do anyway )

    Regards,

    Greg M

  3. #3
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    758

    Re: Amend code to work with time instead of date

    Hi Greg,

    Thanks for your response.

    If I change my code from date to time it doesn't work, so I'm thinking I need to declare time as variable then run my data through.

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Amend code to work with time instead of date

    Hi again,

    I'm probably misunderstanding your requirements, but I was referring to something like:

    Please Login or Register  to view this content.
    Even though the variable is declared as type Date it will accept a Time value, e.g.:

    Please Login or Register  to view this content.

    Does this help?

    Regards,

    Greg M

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Amend code to work with time instead of date

    Understanding the bits and bytes of Dates and Time.

    Excel stores Dates and Times internally as a real number type Double which is similar to type Date.

    The Integer Part of the 'real number' is the Date (number of days since a 'Base Date').
    The fractional Part of the 'real number' the Time of Day.

    For example:
    Please Login or Register  to view this content.
    Lewis

+ 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. Amend VBA code to 'undo' previous run results before re-running code
    By sllewe55 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-14-2017, 08:16 AM
  2. Replies: 5
    Last Post: 10-22-2015, 01:30 PM
  3. [SOLVED] Macro code to amend the status of a cell to be a date
    By katieshields in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-31-2014, 10:00 AM
  4. [SOLVED] How To Amend Data Via Userform (and get spinbox to work correctly)
    By ScotyB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-04-2012, 07:04 PM
  5. Formula to compare and amend date and time
    By Saajan in forum Excel Formulas & Functions
    Replies: 22
    Last Post: 06-03-2010, 04:34 AM
  6. Getting the amend function/code to work correctly
    By terry_pro in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-14-2008, 03:57 AM
  7. Amend filter code to work with combobox
    By macximus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2008, 02:33 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