• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Excel jiggery-pokery

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #11
    Originally posted by BoredBloke View Post
    Sub StripData()
    Dim ws As Worksheet
    Dim lLR As Long
    Dim lRowCounter As Long
    Dim sVal As String
    Dim sDate As String
    Dim sTime As String
    Dim sName As String
    Dim sComment As String
    Dim sTest1 As String
    Dim sTest2 As String
    Dim lOutRow As Long


    lOutRow = 2

    Set ws = ThisWorkbook.Sheets(1)
    lLR = ws.UsedRange.Rows.Count
    For lRowCounter = 2 To lLR
    sVal = ws.Cells(lRowCounter, 1)
    sTest1 = Replace(sVal, "-", "")
    sTest2 = Replace(sVal, ":", "")
    If Len(sVal) - Len(sTest1) >= 3 And Len(sVal) - Len(sTest2) >= 2 Then
    sComment = ""
    lOutRow = lOutRow + 1
    sDate = Left(sVal, 10)
    sTime = Mid(sVal, 11, 9)
    sName = Right(sVal, Len(sVal) - 19)
    ws.Cells(lOutRow, 3) = sDate
    ws.Cells(lOutRow, 4) = sTime
    ws.Cells(lOutRow, 5) = sName
    Else
    If sVal <> "" Then
    sComment = sComment & Chr(10) & sVal
    ws.Cells(lOutRow, 6) = sComment
    End If
    End If
    Next lRowCounter

    Set ws = Nothing


    End Sub
    raw data goes in column A on sheet 1 and output gets dumped to columns CDE&F on the same sheet
    Juts read the bit above, so that won't work!!
    Rule Number 1 - Assuming that you have a valid contract in place always try to get your poo onto your timesheet, provided that the timesheet is valid for your current contract and covers the period of time that you are billing for.

    I preferred version 1!

    Comment


      #12
      Originally posted by BoredBloke View Post
      Juts read the bit above, so that won't work!!
      You're right, it doesn't
      "Being nice costs nothing and sometimes gets you extra bacon" - Pondlife.

      Comment


        #13
        If this is autogenerated, can you assume newest is always on top?

        Comment


          #14
          Originally posted by mudskipper View Post
          If this is autogenerated, can you assume newest is always on top?
          Yes. It is always the top entry I need, but length of content is arbitrary.
          "Being nice costs nothing and sometimes gets you extra bacon" - Pondlife.

          Comment


            #15
            Will the last test of the first line always be "(Customer Updates)" ? (or maybe even just " Updates)"

            This is dirty, and strips out the date/time/etc on the first line... but works:
            =MID(A1,FIND("Updates)",A1,1)+9,(FIND("-20",A1,10)-FIND("Updates)",A1,1))-15)

            This will work for any year in the 21st century as long as "-20" and "Updates)" don't appear in the free text

            or, if you want to include the date & name:
            =LEFT(A1,(FIND("-20",A1,10))-6)

            This will work for any year in the 21st century as long as "-20" doesn't appear in the free text of the most recent comment.

            Might try to refine it some more.
            …Maybe we ain’t that young anymore

            Comment


              #16
              Is all the text wrapped in one cell of is it cell

              A1 =
              12-10-2018 14:12:09 - Joe Bloggs (Customer Updates)
              No change this week as project owner has been on leave.
              A2 =
              05-10-2018 08:24:24 - Jane Blogges (Customer Updates)
              Supplier has produced a more detail proposal for the solution, including a move to an integrated service built on the exiting API's

              Costs yet to be agreed.

              and so on?
              Rule Number 1 - Assuming that you have a valid contract in place always try to get your poo onto your timesheet, provided that the timesheet is valid for your current contract and covers the period of time that you are billing for.

              I preferred version 1!

              Comment


                #17
                Originally posted by BoredBloke View Post
                Is all the text wrapped in one cell of is it cell

                A1 =
                12-10-2018 14:12:09 - Joe Bloggs (Customer Updates)
                No change this week as project owner has been on leave.
                A2 =
                05-10-2018 08:24:24 - Jane Blogges (Customer Updates)
                Supplier has produced a more detail proposal for the solution, including a move to an integrated service built on the exiting API's

                Costs yet to be agreed.

                and so on?
                I believe it's all one cell, otherwise there is no requirement to split out the data.
                …Maybe we ain’t that young anymore

                Comment


                  #18
                  Originally posted by BoredBloke View Post
                  Is all the text wrapped in one cell of is it cell

                  A1 =
                  12-10-2018 14:12:09 - Joe Bloggs (Customer Updates)
                  No change this week as project owner has been on leave.
                  A2 =
                  05-10-2018 08:24:24 - Jane Blogges (Customer Updates)
                  Supplier has produced a more detail proposal for the solution, including a move to an integrated service built on the exiting API's

                  Costs yet to be agreed.

                  and so on?
                  Originally posted by WTFH View Post
                  I believe it's all one cell, otherwise there is no requirement to split out the data.
                  What WTFH said.

                  I need everything from and including the first time stamp up to but excluding the second time stamp.
                  "Being nice costs nothing and sometimes gets you extra bacon" - Pondlife.

                  Comment


                    #19
                    Originally posted by DaveB View Post
                    I need everything from and including the first time stamp up to but excluding the second time stamp.

                    Originally posted by WTFH View Post
                    =LEFT(A1,(FIND("-20",A1,10))-6)

                    This will work for any year in the 21st century as long as "-20" doesn't appear in the free text of the most recent comment.
                    If you need it as VBA it's going to be more complex!

                    Just to explain the logic:
                    Using "LEFT" as you want the first record in the field. Would use "MID" for others, or "RIGHT" for the last record.
                    -20 appears as part of the date 12-10-2018
                    We want to find the second occurrence of the date, so we're looking for "-20" that occurs more than 10 characters in to the field. <note: just realised as typing this that if there is only one record in the field, this will fail, need to rework>
                    Once we find the second "-20" we then need to count back 6 characters as the preceding 6 characters are the start of that date field.
                    …Maybe we ain’t that young anymore

                    Comment


                      #20
                      Ok if all the text is wrapped in one cell (a1) then try this

                      Sub StripData()
                      Dim ws As Worksheet

                      Dim sVal As String
                      Dim sComment As String

                      Dim lOutRow As Long
                      Dim vData As Variant
                      Dim lCounter As Long


                      Set ws = ActiveSheet
                      sVal = ws.Cells(2, 1)
                      lOutRow = 1
                      vData = Split(sVal, Chr(10))
                      For lCounter = 0 To UBound(vData)
                      If IsDate(Left(vData(lCounter), 10)) Then
                      'split out values
                      sComment = ""
                      lOutRow = lOutRow + 1
                      ws.Cells(lOutRow, 2) = Left(vData(lCounter), 10)
                      ws.Cells(lOutRow, 3) = Trim(Mid(vData(lCounter), 12, 8))
                      ws.Cells(lOutRow, 4) = Trim(Right(vData(lCounter), Len(vData(lCounter)) - 23))
                      Else
                      sComment = sComment & vData(lCounter)
                      ws.Cells(lOutRow, 5) = sComment
                      End If
                      Next lCounter

                      Set ws = Nothing


                      End Sub

                      Sorry meant to say this code assumes the data is all in cell A2 (sVal = ws.Cells(2, 1)) row 2, column 1 = A2. It then writes the data out into columns 2 to 5 (b to e) and adds lines as it needs them - would add a screen shot of the output but can't
                      Last edited by BoredBloke; 17 October 2018, 09:41.
                      Rule Number 1 - Assuming that you have a valid contract in place always try to get your poo onto your timesheet, provided that the timesheet is valid for your current contract and covers the period of time that you are billing for.

                      I preferred version 1!

                      Comment

                      Working...
                      X