+ Reply to Thread
Results 1 to 4 of 4

given a string of data in 1 row, how can i create a new row every time a date comes up?

Hybrid View

purelutz given a string of data in 1... 08-04-2017, 03:11 PM
mehmetcik Re: given a string of data in... 08-04-2017, 03:59 PM
purelutz Re: given a string of data in... 08-04-2017, 04:04 PM
mehmetcik Re: given a string of data in... 08-05-2017, 08:58 PM
  1. #1
    Registered User
    Join Date
    05-22-2017
    Location
    sf, ca
    MS-Off Ver
    2010
    Posts
    7

    given a string of data in 1 row, how can i create a new row every time a date comes up?

    can this be done in excel? i don't want to manually start a new row every time there is a date. See attachment and scroll down until you see a lot of data jumbled together for an example. I've started what i want the data to look like at the top of the file. Thanks for the help.

    Example of what the data looks like:
    16-oct 4081931 -4,517.60 check 13454543 16-oct 4081931 -4,517.60 check 13454543 16-oct 4081931 -4,517.60 check 13454543 16-oct 4081931 -4,517.60 check 13454543 16-oct 4081931 -4,517.60 check 13454543

    Example of what i want:
    16-oct 4081931 -4,517.60 check 13454543
    16-oct 4081931 -4,517.60 check 13454543
    16-oct 4081931 -4,517.60 check 13454543
    16-oct 4081931 -4,517.60 check 13454543
    Attached Files Attached Files
    Last edited by purelutz; 08-04-2017 at 03:22 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: given a string of data in 1 row, how can i create a new row every time a date comes up

    In your example all the dates are in Oct.

    Is it normal to have all the dates in one month?

    This Macro will split the active cell into seperate rows as requested. It will work for all months.

    
    Sub Test()
    
    A = ActiveCell.Value
    A = Application.Trim(A)
    
    R = ActiveCell.Row
    
    On Error Resume Next
    
    For MCount = 1 To 12
    
    Pos = 1
    
    SText = "-" & Format(DateValue("01/" & MCount & "/2017"), "MMM")
    
    Loop1:
    
    Pos = InStr(Pos, A, SText)
    
    If Pos = 0 Then GoTo Skip
    
    Pos2 = InStrRev(A, " ", Pos)
    
    If Pos2 = 0 Then Pos = Pos + 1: GoTo Loop1
    Cells(R, 1).Value = Left(A, Pos2 - 1)
    Cells(R + 1, 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    
    A = Right(A, Len(A) - Pos2)
    
    Pos = 1: R = R + 1: GoTo Loop1
    
    Skip:
    Cells(R, 1).Value = A
    
    Next MCount
    
    End Sub
    Last edited by mehmetcik; 08-04-2017 at 05:18 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    05-22-2017
    Location
    sf, ca
    MS-Off Ver
    2010
    Posts
    7

    Re: given a string of data in 1 row, how can i create a new row every time a date comes up

    All october, yes. the day can change though.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: given a string of data in 1 row, how can i create a new row every time a date comes up

    
    Sub Test()
    
    Dim fNameAndPath As Variant
    
    fNameAndPath = Application.GetOpenFilename(FileFilter:="Text Files (*.txt), *.txt", Title:="Select File To Be Opened")
    If fNameAndPath = False Then Exit Sub
    
    Workbooks.OpenText Filename:=fNameAndPath, Origin:=xlMSDOS, _
            StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
            ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=False _
            , Space:=False, Other:=False, FieldInfo:=Array(1, 2), _
            TrailingMinusNumbers:=True
    
    LR = Cells(Rows.Count, 1).End(xlUp).Row
    
    Range("B1:B" & LR).FormulaR1C1 = _
            "=IF(CODE(LEFT(RC[-1],1))=9,RIGHT(RC[-1],LEN(RC[-1])-1),RC[-1])"
    Range("A1:A" & LR).Value = Range("B1:B" & LR).Value
    
    Range("B1:B" & LR).FormulaR1C1 = _
            "=IF(ISNUMBER(LEFT(RC[-1],1)*1),RC[-1],RIGHT(RC[-1],LEN(RC[-1])-FIND(""-"",RC[-1])+3))"
    Range("A1:A" & LR).Value = Range("B1:B" & LR).Value
    
    Range("B1:B" & LR).FormulaR1C1 = _
            "=IF(ISNUMBER(LEFT(RC[-1],1)*1),RC[-1],RIGHT(RC[-1],LEN(RC[-1])-1))"
    Range("A1:A" & LR).Value = Range("B1:B" & LR).Value
    
    For MCount = 10 To 12
    
    LR = Cells(Rows.Count, 1).End(xlUp).Row
    
    SText = "-" & Format(DateValue("01/" & MCount & "/2017"), "MMM")
    
    Columns("A:A").Replace What:=SText, Replacement:=SText & " ", Lookat:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    
        Range("B1:B" & LR).FormulaR1C1 = _
            "=(LEN(RC[-1])-LEN(SUBSTITUTE(RC[-1],""" & SText & ""","""")))/4"
            
        Range("B1:B" & LR).Value = Range("B1:B" & LR).Value
        
            Columns("B:B").Replace What:="1", Replacement:=0, Lookat:=xlWhole, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
            
    Loop2:
    P = Application.Max(Columns(2).Value)
    
    If P = 0 Then GoTo Skip2
    
    Max = 30 + P
    
    Set Z = Columns(2).Find(P, LookIn:=xlValues, Lookat:=xlWhole)
            
    Z.Clear
    
    A = Application.Trim(Z.Offset(0, -1).Value)
    
    R = Z.Row
    
    On Error Resume Next
    
    SText = Left(A, InStr(A, " ") - 1)
    
    Loop1:
    
    Pos = InStr(7, A, SText)
    
    If Pos = 0 Then GoTo Skip
    
    Cells(R, 1).Value = Left(A, Pos - 1)
    Range(Cells(R + 1, 1), Cells(R + 1, 2)).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    
    A = Right(A, Len(A) - Pos + 1)
    
    R = R + 1: GoTo Loop1
    
    Skip:
    
    SText = Left(CStr(Format(DateValue(Replace(SText, "-", "/") & "/" & Year(Date)) + 1, "dd-mmm-yyyy")), 6)
    Max = Max - 1
    If Max > 0 Then GoTo Loop1
    
    Cells(R, 1).Value = A
    
    GoTo Loop2
    
    Skip2:
    Next MCount
    
    
    End Sub

+ 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. Replies: 7
    Last Post: 06-30-2017, 01:07 PM
  2. [SOLVED] Create an 8 digit date string from date
    By JO505 in forum Excel General
    Replies: 3
    Last Post: 04-11-2015, 05:34 PM
  3. Need to separate date/time from a single cell and create a date/time chart
    By slicksilver79 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 06-19-2014, 09:48 PM
  4. Extract date and time from a string
    By pickslides in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-19-2014, 09:07 PM
  5. [SOLVED] Extract time from date and time text string
    By pattem2013 in forum Excel General
    Replies: 5
    Last Post: 09-07-2013, 03:20 AM
  6. Converting text string that contains a date and time to a date
    By jmforde in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-12-2013, 02:31 PM
  7. Need to capture date data in a text string containing a date and time stamp
    By Grilleman in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-07-2013, 01:14 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