Consulting

Results 1 to 3 of 3

Thread: Solved: Complex code needed (Seperate words)

  1. #1

    Solved: Complex code needed (Seperate words)

    I need a code that will look into each cell in column B and find each city separated by “/” and separate each city (along with the rest of the information) into its own row. (See Attached)



    For example…


    California | Antioch / Brentwood / Concord | Contra Costa | $1.00 | $2.00 | $3.00
    California | Antioch| Contra Costa | $1.00 | $2.00 | $3.00
    California | Brentwood| Contra Costa | $1.00 | $2.00 | $3.00
    California | Concord | Contra Costa | $1.00 | $2.00 | $3.00
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,877
    try:
    [vba]Sub spreadOut()
    lastRow = Cells(Rows.count, 1).End(xlUp).Row
    For rw = lastRow To 5 Step -1
    With Cells(rw, 2)
    myArray = Split(.Value, "/")
    If UBound(myArray) > 0 Then
    Cells(rw, 2).Value = Application.Trim(myArray(UBound(myArray)))
    For i = 0 To UBound(myArray) - 1
    Rows(rw).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Rows(rw + 1).Copy Rows(rw)
    Cells(rw, 2).Value = Application.Trim(myArray(i))
    Next i
    End If
    End With
    Next rw
    End Sub
    [/vba] Assumes list starts at row 5
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    AWESOME!!! Thank you p45cal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •