Results 1 to 25 of 25

VBA assistance to modify code

Threaded View

  1. #1
    Registered User
    Join Date
    10-25-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    9

    Smile VBA assistance to modify code

    Hello All,

    I have a piece of code that almost works for what I need it to do.
    Basically, I have data consisting of a variable number of column separated
    strings. example

    01AL,02AL,03AL,04AL

    When I run the code below

    Sub CommaSeparated()
    
    Dim curr_range As Range
    Dim Row As Range
    Dim arr As Variant
    Dim cell As Variant
    Dim output_str As String
    Dim output_arr As Variant
    
    Set curr_range = ActiveSheet.Range("A1:A9999")
        For Each Row In curr_range
            arr = Split(Row, ",")
           	  For Each cell In arr
                output_str = output_str & "," & cell
    
            Next cell
    
        Next Row
            output_str = Replace(output_str, " ", "")
              output_str = Right(output_str, Len(output_str) - 1)
                   output_arr = Split(output_str, ",")
    
        ActiveSheet.Range("A:A").Value = Application.WorksheetFunction.Transpose(output_arr)
    
    End Sub
    It gives me sixteen rows of:

    01AL
    02AL
    03AL
    04AL
    01AL
    02AL
    03AL
    04AL
    01AL
    02AL
    03AL
    04AL
    01AL
    02AL
    03AL
    04AL

    and a #VALUE down the rest of the column

    I was hoping to only get four rows of:

    01AL
    02AL
    03AL
    04AL

    with no #VALUE down rest of column.

    Thank you in advance for any assistance/suggestions.


    Moderator's Note: Please put code tags around codes, select the code then hit "#" sign. I'll do it for you, this time.
    Last edited by vlady; 11-19-2012 at 07:45 PM. Reason: code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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