Solved

Add Comma Separated “;”

Posted on 2011-03-15
11
272 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

696 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