+ Reply to Thread
Results 1 to 12 of 12

Separating text in one cell into individual cells

Hybrid View

Hblbs Separating text in one cell... 01-09-2009, 12:11 PM
mewingkitty Definitely possible 01-09-2009, 12:24 PM
Hblbs Hi Mew, I add these in... 01-09-2009, 12:47 PM
mdbct Insert a sheet called... 01-09-2009, 05:16 PM
Hblbs Hi, thanks for the code, it... 01-11-2009, 03:28 PM
  1. #1
    Registered User
    Join Date
    09-24-2008
    Location
    UK
    Posts
    75

    Separating text in one cell into individual cells

    Hello, I have a spreadsheet which needs formatting I was wondering if anyone would be able to help with creating a macro to do so. The problem with raw report is that in cell A47 there are five columns worth of data in that one cell, then in B48 there are another two, in b49 and b50 one respectively. I manually format it by first joining the separate cells using

    =A47&” “&B48&” “&b49&” “&b50
    Then convert text to columns. There are 4 tables of data in the Raw report sheet, D – HB / CTB and C – HB / CTB which I join to create into 1 table, but I index each table D – HB and D – CTB ect so that I can use this to filter the table. The raw report always comes out in this format but can vary in length, i.e the amount of records it produces, I was hoping to save some time formatting this as I need to do this on a regular basis.


    I’ve attached the file to show how the raw report is received and how it needs to end up. I have no knowledge of how to write VBA.

    I hope this makes sense, thanks in advance.

    If this is not possible or its not the done thing to request a macro from scratch please let me know and I will delete.
    Last edited by Hblbs; 01-22-2009 at 10:44 AM.

  2. #2
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Definitely possible

    It can definitely be done, and you're not asking too much.
    Heck if I have time today, and no one else has got around to it, I'll take a crack at it just for practice (I still have a lot to learn about this as well!). The cells all have exactly the same number of characters, so it could even be done with formulas.

    mew!

    EDIT:
    One question, where are the D, HB, CHB, etc. coming from on the second page?
    Last edited by mewingkitty; 01-09-2009 at 12:31 PM.
    =IF(AND(OR(BLONDE,BRUNETTE,REDHEAD),OR(MY PLACE,HER PLACE),ME),BOW-CHICKA-BOW-WOW,ANOTHER NIGHT ON THE INTERNET)

  3. #3
    Registered User
    Join Date
    09-24-2008
    Location
    UK
    Posts
    75
    Quote Originally Posted by mewingkitty View Post
    It can definitely be done, and you're not asking too much.
    Heck if I have time today, and no one else has got around to it, I'll take a crack at it just for practice (I still have a lot to learn about this as well!). The cells all have exactly the same number of characters, so it could even be done with formulas.

    mew!

    EDIT:
    One question, where are the D, HB, CHB, etc. coming from on the second page?
    Hi Mew, I add these in myself. Once all the data is separated in each cell and 1 row. At the begining of the table just after Breakdown there is the D records (HB) - cell A36, at the end of each table there is a Total (Total : 203) in cell A860 and 2 cells below that another table begins with the same column titles. Its used to index the data so I know which table these came from. Another thing is it always starts D - HB, the D (CTB), then C (HB), then C (CTB). Hope this helps.

  4. #4
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848
    Insert a sheet called "Transferred" into your workbook. Switch back to your raw data sheet.

    Run the following macro:
    Sub combineDate()
        Dim strLong As String, i As Long, lRow As Long, lStart As Long
        Dim strAlpha As String, strCat As String, iGap As String
        lRow = Cells(Rows.Count, 1).End(xlUp).Row
    
        For i = 1 To lRow
            If InStr(Cells(i, 1), "BREAKDOWN") > 0 Then
                lStart = i
            End If
        Next
    
        For i = lStart To lRow
            If InStr(Cells(i, 1), "Records") > 0 Then
                strAlpha = Left(Cells(i, 1), 1)
                strCat = Replace(Mid(Cells(i, 1), InStr(Cells(i, 1), "(") + 1, 3), ")", "")
            End If
    
            If strCat = "CTB" Then
                iGap = ""
            Else
                iGap = "  "
            End If
    
            If InStr(Cells(i, 1), "/") > 0 Then
                strLong = Cells(i, 1) & iGap & Cells(i + 1, 2) & " " & Cells(i + 2, 2) & " " & Cells(i + 3, 2)
                Worksheets("transferred").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = strLong
                Worksheets("transferred").Cells(Rows.Count, 1).End(xlUp).Offset(0, 10) = strAlpha
                Worksheets("transferred").Cells(Rows.Count, 1).End(xlUp).Offset(0, 11) = strCat
    
            End If
    
    
    
        Next
    
        Worksheets("Transferred").Activate
        Range("a:a").Select
        Application.DisplayAlerts = False
        Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
                                FieldInfo:=Array(Array(0, 2), Array(11, 2), Array(19, 1), Array(20, 2), Array(32, 1), _
                                                 Array(55, 1), Array(80, 1), Array(119, 1), Array(143, 1), Array(145, 1))
        Application.DisplayAlerts = True
        Cells(1, 3).EntireColumn.Delete
        Range("d:g").NumberFormat = "yyyy-mm-dd hh:mm:ss.000"
    
    
    End Sub
    I didn't include any of the headings or the coloring or the info above the re-organized data.

  5. #5
    Registered User
    Join Date
    09-24-2008
    Location
    UK
    Posts
    75
    Hi, thanks for the code, it works up to a point. For some reason it does not separate text to columns, the data is all in one cell, a message box appears after the Macro is run "Microsoft Visual Basic . X . 400". Also it does not include the other 3 cells directly below which need to be aligned to the same row and if possible the headings too, although none of the colouring is needed.

    Thank you for taking the time to create this though as it still save me vast amounts of time as I do this a number of times during the week. Appreciate any/all other input in this. Thanks
    Last edited by Hblbs; 01-11-2009 at 03:49 PM. Reason: deleted spurious quote

  6. #6
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    eep

    I wrote one that had some kinks in it, but never finished it off because I saw someone else post here. I'll send it your way tomorrow if you still don't have an answer by then.

    mew.

    Eh
    re-wrote one, it's pretty... crude.

    Works, mostly, not sure what's happening with the format of the dates half way through though. So yeah, save a copy of the original. :P

    mew
    Attached Files Attached Files
    Last edited by mewingkitty; 01-13-2009 at 12:09 AM.

+ 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