+ Reply to Thread
Results 1 to 9 of 9

Defragment a field that contains time data to morning and evening time

Hybrid View

  1. #1
    Registered User
    Join Date
    01-11-2019
    Location
    iraq
    MS-Off Ver
    office 2016
    Posts
    12

    Defragment a field that contains time data to morning and evening time

    Hi
    I have a spreadsheet in Excel that contains a C field for time-merged data
    AM and PM in cell
    I need to separate and insert the first time am in column D
    And insert the last time PM in column E
    using VBA Excel
    thank you
    i attach excel For Example
    Attached Files Attached Files
    Last edited by aabonargis; 06-12-2019 at 12:18 PM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,616

    Re: VBA Code EXCEL

    Title more descriptive
    Last edited by Pepe Le Mokko; 06-13-2019 at 03:06 AM.

  3. #3
    Registered User
    Join Date
    01-11-2019
    Location
    iraq
    MS-Off Ver
    office 2016
    Posts
    12

    Re: VBA Code EXCEL

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however the thread title does not really convey what your request is about.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    I do not know what is the appropriate name for my topic
    Can you help me with the right name?

  4. #4
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,494

    Re: VBA Code EXCEL

    ___________________________

    I do not think you need VBA for this.
    With a LEFT() and RIGHT() function you can also get the first and last part of a merged string.

    please look at attached file for the formulas to use.
    Attached Files Attached Files
    Last edited by Roel Jongman; 06-12-2019 at 12:22 PM. Reason: OP changed title so removed (other) titile suggestion

  5. #5
    Registered User
    Join Date
    01-11-2019
    Location
    iraq
    MS-Off Ver
    office 2016
    Posts
    12

    Re: Defragment a field that contains time data to morning and evening time

    I do not think you need VBA for this.
    With a LEFT() and RIGHT() function you can also get the first and last part of a merged string.
    This is not the right solution
    The appropriate solution is to display the AM time only in column D
    The PM time is displayed only in column E
    thanks

  6. #6
    Registered User
    Join Date
    01-11-2019
    Location
    iraq
    MS-Off Ver
    office 2016
    Posts
    12

    Re: Defragment a field that contains time data to morning and evening time

    For UP

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Defragment a field that contains time data to morning and evening time

    A small UDF should work:

    Function ChooseTime( _
        ByVal TimeList As String, _
        ByVal Period As String, _
        Optional ByVal Delimiter As String)
        
        Dim sList() As String
        Dim s As Variant
        Dim t As Date
        Dim ts As Date
        
        If Delimiter = "" Then Delimiter = " "
        sList = Split(TimeList, Delimiter)
        For Each s In sList
            ts = TimeValue(s)
            Select Case Period
                Case "AM"
                    If ts < TimeSerial(12, 0, 0) And (ts < t Or t = 0) Then t = ts
                Case "PM"
                    If ts >= TimeSerial(12, 0, 0) And (ts > t Or t = 0) Then t = ts
            End Select
        Next s
        ChooseTime = IIf(t > 0, t, "")
    End Function
    In D2, enter:
    Formula: copy to clipboard
    =ChooseTime($C2,"AM"," ")


    In E2, enter:
    Formula: copy to clipboard
    =ChooseTime($C2,"PM"," ")


    Copy down.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  8. #8
    Registered User
    Join Date
    01-11-2019
    Location
    iraq
    MS-Off Ver
    office 2016
    Posts
    12

    Re: Defragment a field that contains time data to morning and evening time

    thank you very match
    thank you for help me

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Defragment a field that contains time data to morning and evening time

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. You may also 'Add Reputation' to those who helped. Thanks.

+ 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. VB Code in Outlook VB code to delete excel files from certain folder
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2018, 02:47 PM
  2. [SOLVED] Excel VB code. Message pops up while code running asking question. Code must not wait.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2014, 06:10 AM
  3. [SOLVED] Excel Macro Visual Basic code not looking at all sheets with second section of code.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2014, 08:26 AM
  4. Replies: 1
    Last Post: 11-13-2013, 10:28 AM
  5. Adding Text to another cell VB code (Help Tweeking code) (Excel 2007)
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2012, 11:37 AM
  6. Code for email alerts from excel isn't working, wrong code possibly?
    By jessthorogood in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2012, 01:45 AM
  7. Importing Excel Macros Code from another Excel sheet which has Macro code.
    By arun.pillai in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2010, 05:38 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