Solved

Add Comma Separated “;”

Posted on 2011-03-15
11
270 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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

Technology Partners: 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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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.

739 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