Results 1 to 18 of 18

Thread: [RESOLVED] Excell: converting comma-separated array

Threaded View

  1. #16

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    9

    Re: Excell: converting comma-separated array

    Hey,

    Thank you very much for your help guys!

    Keywords:

    cell, replace, Visual, Basic, Excell, delete, row, content, array, comma, separated, covert, automate

    Here is what I made in the end:

    VB Code:
    1. Option Explicit
    2.  
    3. Sub arseniy_commas()
    4. Const sSeparator As String = ", " 'The value to be used to split the cells
    5.  
    6. Dim rngSource As Range
    7. Dim saResults() As String
    8. Dim numberRows As Integer
    9. Dim lItemNum As Long
    10.  
    11.     'Start in cell C1
    12.     Set rngSource = ThisWorkbook.Worksheets(1).Range("C1")
    13.    
    14.     'Loop through all used cells in Column C
    15.     Do While rngSource.Value <> ""
    16.        
    17.         saResults = Split(rngSource.Value, sSeparator)
    18.        
    19.         numberRows = UBound(saResults)
    20.        
    21.         rngSource.Offset(1).EntireRow.Resize(numberRows).Insert
    22.         rngSource.EntireRow.Copy rngSource.EntireRow.Offset(1).Resize(numberRows).EntireRow
    23.        
    24.         On Error Resume Next
    25.                            
    26.         'Loop through each item in the array
    27.         For lItemNum = LBound(saResults) To UBound(saResults)
    28.             'Writing the value to the next cell below the source cell
    29.             rngSource.Offset(lItemNum, 0).Value = saResults(lItemNum)
    30.         Next lItemNum
    31.            
    32.  
    33.            
    34.         'Move to the next source cell in column
    35.         Set rngSource = rngSource.Offset(lItemNum, 0)
    36.        
    37.     Loop
    38.  
    39.     Set rngSource = Nothing
    40. End Sub

    Attached is the example of how it works.

    Cheers!
    Attached Files Attached Files

Posting Permissions

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



Click Here to Expand Forum to Full Width