+ Reply to Thread
Results 1 to 15 of 15

Extract multiple date and time values to multiple rows

  1. #1
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Extract multiple date and time values to multiple rows

    In cell A1 there are 5 date and time values. How to extract all data to rows 1 to 5 etc... using VBA ?

    I'm not able to upload a file as example at his moment, so:

    e.g. cell A1 contains 27/08/2012 om 14:33 28/08/2012 om 18:33 29/08/2012 om 19:33 30/08/2012 om 16:33 01/09/2012 om 12:33 etc ...
    Row 1 needs to be extracted to rows 1 to 5 with values:
    • A1 - 27/08/2012 | B1 - 14:33
    • A2 - 28/08/2012 | B2 - 18:33
    • A3 - 29/08/2012 | B3 - 19:33
    • A4 - 30/08/2012 | B4 - 16:33
    • A5 - 01/09/2012 | B5 - 12:33


    Thank you.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Extraxt multiple date and time values to multiple rows

    Hi, WilliamV,

    if Data is always laid down as in your example and in this example there is enough empty cells under the given Data:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Extraxt multiple date and time values to multiple rows

    Holger, thank you, this does the job.
    Only thing left to do know is to copy the entire row. In your code only the values of A are splitted into A & B over needed rows, but the data from all other columns must be copied as well. So if the first row has 10 columns (A to J), these columns must be pasted as well.

    Also, can it be applied to a range, e.g. K1:K ? Say in column K there are multiple rows with multiple values, how to extract those to needed rows with colomn K and L ?

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Extraxt multiple date and time values to multiple rows

    Hi, WilliamV,

    if the range is filled and I have to insert I prefer to work from the bottom up. For this example I suggested that the last line of data in K should be the start for working the way up and splitting the contents.

    Please Login or Register  to view this content.
    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Extract multiple date and time values to multiple rows

    Holger, ok, thank you.

    I would like to apply this code to included file Uitrapport.xls. You will find a file Uitrapport_filter.xls as well. This last one imports (through VBA) data from the first one. When openening it will ask to select a source file, you need to select the file Uirapport.xls. I have used VBA and formula's to obtain needed results. In column N you can find the date- and timedata. At this moment, i only use a formula to extract the time data in format from HH:MM to HH:MM, and i extend this formula manually to the available range.
    I would like to apply your above code to extract dates (if multiple present) and concerning times (per date, from and till). Multiople dates imply multiple rows, as in your examples above.

    Can you help me out with this? Thank you.
    Last edited by WilliamV; 10-18-2012 at 03:03 AM. Reason: correction

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Extract multiple date and time values to multiple rows

    Hi, WilliamV,

    according to the workbook in Column N the header is Lange beschrijving, and there are no date and time sequences as far as the Autofillter says. Can you help me out with that, please?

    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Extract multiple date and time values to multiple rows

    Holger,

    Strange.
    The Header with date and time sequences is named Tijdsinfo samenvatting. When i open the workbook UitRapport.xls this is situated in column N. When you open the workbook UitRapport_filter the data is placed into the G-column.

    Hope this clarifies things... Thank you again.
    Grtz, William.

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Extract multiple date and time values to multiple rows

    Hi, William,

    okay, I got that one. But of I look at the first line another question occurs to me.

    Contents in G2 is
    Please Login or Register  to view this content.
    No problem for the time but a small problem concerning about the dates. To me this would mean fill up a range of dates from 05/09/12 to 12/06/13 where the weekdays meet the weekdays indicated inside the parentheses (Sun, Mon, Tue, Thur, Fri - correct me if Iīm wrong with figuring these out). So shall just be these or should all dates be added?

    Ciao,
    Holger

  9. #9
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Extract multiple date and time values to multiple rows

    Well Holger, good you mention this, i've overseen it.

    To situate: the workbook is an extract of an event database. We need to 'model' this to our needs for generating an event booklet every month.

    The example in G2 is a reoccuring event: from 05/09/12 till 12/06/13 every wednesday from 18:40 till 21:35. The other days (yes, you did interpret it well: Sun, Mon, Tue, Thur, Fri) just stand for 'event closed (in dutch = gesloten, in german = geschlossen )' or 'event not taking place' so these have no importance and may be ignored.
    So, to answer your question: above example should be converted to all wednesdays between the mentioned date range. This maybe can be obtained by a condition: day (e.g. woensdag) from (=van) ... till (=tot) ... ?
    Note: If no time is given (e.g. G27) only the date range counts and all of the rest may be ignored.

    I hope this clarifies ... Thank you again for the efforts taken.
    Grtz, William.

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Extract multiple date and time values to multiple rows

    Hi, william,

    I must ask you for a little patience with that macro - I didnīt expect the question to dive in that deep into my free weekend. Up to now the dates create a slight unease to me as I will have to handle both the dates as well as the weekdays - letīs see how things will develop.

    Ciao,
    Holger

  11. #11
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Extract multiple date and time values to multiple rows

    Hi, WilliamV,

    Iīm running into problems earlier to the one point where I expected them as I donīt find the consistency as I expected.

    I started with the easy part, checking the first 2 letters of the string and then decide what to do.

    No problem for
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    but creating wrong data for
    Please Login or Register  to view this content.
    as the colored dates have no times and match up exactly to the pattern which is used for offsetting the array (showing 3x weekday and date).

    Right now Iīm sort a helpless for finding a way to work around this as even the use of comma as a delimiter isnīt consistent throughout the data. What I may think of is comparing each item of the array and use a variable to even up to the consistency needed for the counter in the loop (Iīm no friend of mingling around with extra variables which influence the counter).

    Iīll take a walk right now and think about it, maybe some fresh air will clean up my thoughts and help me with a maybe better and more suitable way to solve this problem.

    Ciao,
    Holger

  12. #12
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Extract multiple date and time values to multiple rows

    Holger,

    Thank you for your patience and endurance

    Yes, if no time values present it can become difficult. That is a major problem when being dependent of data input by third parties ... and this can be very frustrating as well

    If no solution possible, i suggest that only in case of multiple date and time use (as you mention above), dates without time values will be ignored. Unless you find a way ...

    Thank you.
    Grtz, William.

  13. #13
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Extract multiple date and time values to multiple rows

    Hi, WilliamV,

    I would kindly ask you to test this limited version which I came about to write in the meantime.

    Limitations are: itīs only working on the ActiveCell (that was for my testing), I left out the holidays (indicated by gesloten without a bracket in the text), I do have problems with the time span if only one is indicated at the end of the string (that should mean the time for each and any date or not?).

    I know this code badly needs a tuning. Feel free to report any bugs and errors.

    Please Login or Register  to view this content.
    Ciao,
    Holger

  14. #14
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Extract multiple date and time values to multiple rows

    Holger,

    Your macro works like a charm (for the ActiveCell).
    Only: the time data is extracted to existing columns (the next 2 columns in line) and thus overwrite existing data.

    Important! Cells do not must be splitted if:
    • no specific days are specified (e.g. van 27/10/2012 tot 4/11/2012)
    • text Altijd open is mentioned
    • text open is present (e.g. maandag open, dinsdag open, ...) and the time span is not present
    An event example for higher mentioned items (to better understand) could be an exhibition taking place from e.g. 27/10/2012 till 4/11/2012. I hope this doesn't complicate things too much ...

    Regarding the single time span: you are right, this does counts for each and any date.

    Next step is to apply this macro to a range (e.g. N1:N) and to automate like in my earlier example.

    Thank you in advance (again!) for this superb and very time-consuming help!

    Grtz, William.

  15. #15
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Extract multiple date and time values to multiple rows

    Hi, WilliamV,

    back again

    About the inserting of two columns for not overwríte data: can be done by something like this:

    Please Login or Register  to view this content.
    I started putting the code to run in a loop from the bottom up - and got stuck on the very first line of data with an error. I doubt it is a very good idea to code every possible combination into the code.

    As I donīt know how the data is coming to you it might be a better way to start and look at the contents of the cells and change them in a way to get a more consistent data with less exceptions to code for (that would make the code easier to maintain instead of writing new parts for any possible mistake that could appear). Like I said maybe thereīs a way to straighten up the data - depending on how the data is delivered (easiest thing would be if you would supply a template to be filled where you could influence the data to yous/my needs).

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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