+ Reply to Thread
Results 1 to 4 of 4

Trying to modify this 'text to rows' code to only use semicolons as delimiters

Hybrid View

  1. #1
    Registered User
    Join Date
    01-23-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question Trying to modify this 'text to rows' code to only use semicolons as delimiters

    Hello All,

    I've been trying to modify the below code to only require one semicolon as a delimiter between the data I need separated.

    I currently have data like this 'John Smith;Ed Jones;Bob Thomas' which is all in a single cell, but I want to separate the names into individual rows, copying and inserting the data from all of the rows like this current code does.

    I believe I can omit most of the bottom half since I'm only dealing with one delimiter, not parenthesis and brackets like this macro does.

    Please let me know if you need any other information.

    Sub Macro1() 
         '
        Dim lngRow As Long 
        Dim strTemp As String 
        Dim intPos As Integer 
        Dim intPosEnd As Integer 
        Dim lngRow2 As Long 
        Dim intCityCol As Integer 
         
        intCityCol = 1 
        lngRow = 2 
        With ActiveSheet 
            Do While .Cells(lngRow, intCityCol) <> "" 
                lngRow2 = lngRow 
                strTemp = .Cells(lngRow, intCityCol) 
                intPos = InStr(strTemp, "[") 
                If intPos > 0 Then 
                    intPosEnd = InStr(intPos, strTemp, "]") 
                    If intPosEnd > 0 Then 
                        lngRow2 = lngRow2 + 1 
                        .Rows(lngRow).Copy 
                        .Rows(lngRow).Insert Shift:=xlDown 
                        .Cells(lngRow + 1, intCityCol) = Mid(strTemp, intPos + 1, intPosEnd - intPos - 1) & Right(strTemp, 4) 
                        strTemp = Left(strTemp, intPos - intCityCol) & Trim(Mid(strTemp, intPosEnd + 1)) 
                        .Cells(lngRow, intCityCol) = strTemp 
                    End If 
                End If 
    ;;------- I don't think I need this part since I don't have multiple delimiters (but not sure) ---
                intPos = InStr(strTemp, "(") 
                If intPos > 0 Then 
                    intPosEnd = InStr(intPos, strTemp, ")") 
                    If intPosEnd > 0 Then 
                        lngRow2 = lngRow2 + 1 
                        .Rows(lngRow).Copy 
                        .Rows(lngRow).Insert Shift:=xlDown 
                        .Cells(lngRow + 1, intCityCol) = Mid(strTemp, intPos + 1, intPosEnd - intPos - 1) & Right(strTemp, 4) 
                        strTemp = Left(strTemp, intPos - 1) & Trim(Mid(strTemp, intPosEnd + 1)) 
                        .Cells(lngRow, intCityCol) = strTemp 
                    End If 
                End If 
    ;; -----------------------------------------------------------------------
                lngRow = lngRow2 + 1 
            Loop 
        End With 
    End Sub
    Thanks!
    Mike

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,627

    Re: Trying to modify this 'text to rows' code to only use semicolons as delimiters

    To attach a Workbook
    (please do not post pictures of worksheets)
    • Click Advanced (next to quick post),
    • Scroll down until you see "Manage Attachments",
    • Click that then select "add files" (top right corner).
    • Click "Select Files" find your file, click "open" click "upload"
    • Once the upload is completed the file name will appear below the input boxes in this window.
    • Click "Done" at bottom right to close the Attachment Manager.
    • Click "Submit Reply"
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    01-23-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Trying to modify this 'text to rows' code to only use semicolons as delimiters

    Thank you for the information protonLeah, please see the attachment below. In the current worksheet I'm only concerned with users in the 6th column (F). Also, I'm getting closer to what I'm looking for with the below code, but now it's separating the names and then leaving the original names in the original field, if that makes any sense.


    Option Explicit
    Sub Macro1()
         '
        Dim fullRow As Long
        Dim fullRow2 As Long
        Dim strTemp As String
        Dim intPos As Integer
        Dim intNameCol As Integer
         
        intNameCol = 6
        fullRow = 2
        With ActiveSheet
            Do While .Cells(fullRow, intNameCol) <> ""
                fullRow2 = fullRow
                strTemp = .Cells(fullRow, intNameCol)
                intPos = InStr(strTemp, ";")
                If intPos > 0 Then
                        fullRow2 = fullRow2 + 1
                        .Rows(fullRow).Copy
                        .Rows(fullRow).Insert Shift:=xlDown
                        .Cells(fullRow + 1, intNameCol) = Mid(strTemp, intPos + 1, intPos + 30)
                        .Cells(fullRow, intNameCol) = strTemp
                End If
                fullRow = fullRow2 + 1
            Loop
        End With
    End Sub

    -Mike
    Attached Files Attached Files
    Last edited by MKBR; 01-24-2014 at 01:22 PM.

  4. #4
    Registered User
    Join Date
    01-23-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Trying to modify this 'text to rows' code to only use semicolons as delimiters

    I kept plugging away at this and was able to accomplish what I needed with the following. The find and replace below the variables removes the OU information from the users.

    Option Explicit
    Sub Macro1()
         '
        Dim fullRow As Long
        Dim fullRow2 As Long
        Dim strTemp As String
        Dim intPos As Integer
        Dim intNameCol As Integer
         
        Cells.Find(What:="(*)", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
            , SearchFormat:=False).Activate
        Cells.FindNext(After:=ActiveCell).Activate
        Cells.Replace What:="(*)", Replacement:="  ", LookAt:=xlPart, SearchOrder _
            :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
         
        intNameCol = 5
        fullRow = 2
        With ActiveSheet
            Do While .Cells(fullRow, intNameCol) <> ""
                fullRow2 = fullRow
                strTemp = .Cells(fullRow, intNameCol)
                intPos = InStr(strTemp, ";")
                If intPos > 0 Then
                        fullRow2 = fullRow2 + 1
                        .Rows(fullRow).Copy
                        .Rows(fullRow).Insert Shift:=xlDown
                        .Cells(fullRow + 1, intNameCol) = Mid(strTemp, intPos + 3)
                        strTemp = Left(strTemp, intPos - intNameCol)
                        .Cells(fullRow, intNameCol) = strTemp
                End If
                fullRow = fullRow2 + 1
            Loop
        End With
    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. [SOLVED] Sort Text into Rows by Multiple Delimiters/Values
    By BoostThis in forum Excel General
    Replies: 6
    Last Post: 11-22-2013, 12:31 PM
  2. [SOLVED] Modify code to transpose a stack of data to rows on to delimit on text hone number field
    By coachtim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-26-2012, 02:52 PM
  3. Modify VBA code to hide blanks rows
    By Ranew in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-17-2011, 09:33 AM
  4. Question on Delimiting Text in Cell for phrases before and after semicolons
    By undergraduate in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2010, 04:41 AM
  5. Replies: 4
    Last Post: 06-13-2006, 07:25 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