Solved

Add Comma Separated “;”

Posted on 2011-03-15
11
268 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

829 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