Results 1 to 7 of 7

Macro to Extract Time from Columns Containing Dates

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Macro to Extract Time from Columns Containing Dates

    I have Dates and Times in Cols B & D from row 2 onwards

    I have tried to write code to move the Times from Col B to C and from Col D to E but cannot get this to work


    Kindly test & amend my code

     Sub MoveTimeValues()
        Dim lastRow As Long
        lastRow = Cells(Rows.Count, "B").End(xlUp).Row
        
        'Loop through each row in columns B and D
        For i = 2 To lastRow
            'Extract the time portion of the date-time value in column B and move it to column C
            Cells(i, "C").Value = Format(Cells(i, "B").Value, "hh:mm AM/PM")
            
            'Extract the time portion of the date-time value in column D and move it to column E
            Cells(i, "E").Value = Format(Cells(i, "D").Value, "hh:mm AM/PM")
        Next i
    End Sub

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Extract time across columns in blocks of 30 minutes
    By jeffreybrown in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-17-2021, 08:17 PM
  2. Replies: 6
    Last Post: 02-26-2021, 01:37 PM
  3. [SOLVED] Extract record on multiple dates criteria & copy to different sheet with macro
    By sanjuss2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-21-2019, 03:25 AM
  4. [SOLVED] Macro that compares 2 dates. I need to extract just date, first
    By lcgar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2016, 10:36 AM
  5. [SOLVED] macro needed to extract specific columns out of multiple columns with their row data
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-07-2014, 12:49 AM
  6. Replies: 5
    Last Post: 11-15-2010, 10:56 PM
  7. Macro to extract specific Columns
    By bholabhala in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2010, 07:45 PM

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