Solved

Add Comma Separated “;”

Posted on 2011-03-15
11
266 Views
Last Modified: 2012-05-11
Hi Experts,

I would like to request Experts help create macro to add Comma Separated “;” at end of the all value under column “Number”. E.g.

Number
500392;
500392;
694682;
694682;
575512;
575575;
 
Hope Experts will help me to create this feature. Attached the workbook for Experts perusal.



Comma.xls
0
Comment
Question by:Cartillo
  • 5
  • 5
11 Comments
 

Expert Comment

by:kenwest3
ID: 35141693
format cell as special
add placeholder for the numberics
add ; at the end then you are done
0
 

Author Comment

by:Cartillo
ID: 35141795
Hi kenwest3,

I'm intent to add this separator at number automatically while running at sub. Hope you can help to create a macro so that I can call this macro with other sub.  
0
 
LVL 20

Expert Comment

by:pari123
ID: 35141982
assuming your data is in column A, you can do this -
Sub addme()
    For i = 1 To Cells(65536, "A").End(xlUp).Row
        If Right(Range("A" & i), 1) <> ";" Then
            Range("A" & i) = Range("A" & i) & ";"
        End If
    Next
End Sub

Open in new window

0
 
LVL 20

Expert Comment

by:pari123
ID: 35142023
If you have empty cells within the same row and you don't want to add the ";" to the cells then you can also try this -
this code will skip empty cells.


Sub addme()
    For i = 1 To Cells(65536, "A").End(xlUp).Row
        If Right(Range("A" & i), 1) <> ";" And Range("A" & i) <> "" Then
            Range("A" & i) = Range("A" & i) & ";"
        End If
    Next
End Sub

Open in new window

0
 

Author Comment

by:Cartillo
ID: 35142180
Hi,

Can we at ";" at these Columns  as well (D2,G2,J2,M2,P2)?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 20

Expert Comment

by:pari123
ID: 35142226
Hi Cartillo,

I think that is possible. "Borrowing" some code from your SearchData Macro, I modified the following - can you please try this once?


thanks,
Ardhendu
Sub addme()
    Set ws = ActiveSheet    ' SELECT CURRENT SHEET
    Set Rng = ws.Range("A1:Z65536")    ' DEFINE RANGE
    For Each Col In Rng.Columns    ' START SEARCHING THE RANGE FOR EMPTY COLUMNS
        For i = 1 To Cells(65536, Mid(Col.Address, 2, 1)).End(xlUp).Row
            If Right(Range(Mid(Col.Address, 2, 1) & i), 1) <> ";" And Range(Mid(Col.Address, 2, 1) & i) <> "" Then
                Range(Mid(Col.Address, 2, 1) & i) = Range(Mid(Col.Address, 2, 1) & i) & ";"
            End If
        Next
    Next
End Sub

Open in new window

0
 

Author Comment

by:Cartillo
ID: 35142283
Hi Ardhendu,

It works but need to omit Type columns. Only data under "Number" columns need to be added with ":". Please help.
0
 
LVL 20

Expert Comment

by:pari123
ID: 35142310
Hi Cartillo, do you want this to be only in the following columns -

D,G,J,M and P?
0
 

Author Comment

by:Cartillo
ID: 35142340
Hi Hi Ardhendu,

Yes you're right, from A2, D2,G2,J2,M2,P2 (please omit first row).
0
 
LVL 20

Accepted Solution

by:
pari123 earned 500 total points
ID: 35142579
Ok,
i think i got this.. try this now.


Sub addme()
'Column A
    For i = 2 To Cells(65536, "A").End(xlUp).Row
        If Right(Range("A" & i), 1) <> ";" And Range("A" & i) <> "" Then
            Range("A" & i) = Range("A" & i) & ";"
        End If
    Next
' Column D
    For i = 2 To Cells(65536, "D").End(xlUp).Row
        If Right(Range("D" & i), 1) <> ";" And Range("D" & i) <> "" Then
            Range("D" & i) = Range("D" & i) & ";"
        End If
    Next
'Column "G"
    For i = 2 To Cells(65536, "G").End(xlUp).Row
        If Right(Range("G" & i), 1) <> ";" And Range("G" & i) <> "" Then
            Range("G" & i) = Range("G" & i) & ";"
        End If
    Next
'Column "J"
    For i = 2 To Cells(65536, "J").End(xlUp).Row
        If Right(Range("J" & i), 1) <> ";" And Range("J" & i) <> "" Then
            Range("J" & i) = Range("J" & i) & ";"
        End If
    Next
'Column "M"
    For i = 2 To Cells(65536, "M").End(xlUp).Row
        If Right(Range("M" & i), 1) <> ";" And Range("M" & i) <> "" Then
            Range("M" & i) = Range("M" & i) & ";"
        End If
    Next
'Column "P"
    For i = 2 To Cells(65536, "P").End(xlUp).Row
        If Right(Range("P" & i), 1) <> ";" And Range("P" & i) <> "" Then
            Range("P" & i) = Range("P" & i) & ";"
        End If
    Next
End Sub

Open in new window

0
 

Author Closing Comment

by:Cartillo
ID: 35143312
Cool! Thanks a lot for the superb solution
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now