Consulting

Results 1 to 4 of 4

Thread: Solved: Add commas on each line into cells

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Solved: Add commas on each line into cells

    I have a some data on my excel file .

    Now I want to add a comma to first of each line on cell and after that remove the lines and all data an each cell will be in 1 line on that cell

    if I have data on cell A1 like this

    DAT-565912
    Replaced No
    20405503
    11700352
    ZM2906923

    I want A1 to be (added comma and removed the line break )

    DAT-565912,Replaced No,20405503,11700352,ZM2906923

    Thank you
    Attached Files Attached Files

  2. #2
    VBAX Contributor GarysStudent's Avatar
    Joined
    Aug 2012
    Location
    Lakehurst, NJ, USA
    Posts
    127
    Location
    Give this a try:

    [VBA]Sub qwerty()
    Dim s As String, v As Variant, r As Range
    s = Chr(10)
    For Each r In ActiveSheet.UsedRange
    v = r.Value
    If InStr(v, s) > 0 Then
    r.Value = Replace(v, s, ", ")
    End If
    Next
    End Sub
    [/VBA]
    Have a Great Day!

  3. #3
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Thank you very much , it is work . Thank you again .

  4. #4
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    It can be done through FIND and REPLACE box as well.
    1] Press CTRL + H
    2] Select the Range concerned
    3] Find what: CTRL + J equivalent to line breaj
    4] Replace with: , i.e. comma
    5] Hit Replace all...
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

Posting Permissions

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