Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add Comma Separated “;”

Posted on 2011-03-15
11
Medium Priority
?
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Ardhendu Sarangi
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 20

Expert Comment

by:Ardhendu Sarangi
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:Ardhendu Sarangi
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:Ardhendu Sarangi
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:
Ardhendu Sarangi earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

618 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