Adding strings using macros

U

ultrarev

010630412
010630412
010630412
010630412
010630412
010630412
010630512
010630512
010630512
010630512
010630512

That is my line how can I make it look like this :

010630412-1
010630412-2
010630412-3
010630412-4
010630412-5
010630412-6
010630512-7
010630512-8
010630512-9

basically adding dash 1,2,3 and so fourth to every line without changing the
first set of numbers? Is this possible please explain.
 
M

Mike H

Hi,

I've assumed this data are in column A. Right click your sheet tab, view
code and paste this in and run it.

Sub merge()
x = 1
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
c.Value = c.Value & "-" & x
x = x + 1
Next
End Sub

Mike
 
D

Don Guillett

sub AddX()
for i=1 to cells(rows.count,"a").end(xlup).row
cells(i,"a").value=cells(i,"a")&"-"& i
next i
end sub
 
U

ultrarev

Thank you sooooooo much!!!!!!

Mike H said:
Hi,

I've assumed this data are in column A. Right click your sheet tab, view
code and paste this in and run it.

Sub merge()
x = 1
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
c.Value = c.Value & "-" & x
x = x + 1
Next
End Sub

Mike
 
U

ultrarev

Is it possible to insert new rows, example:

21-416B,C,P,R

and have it look like this:

21-416B
21-416C
21-416P
21-416R

I would greatly appreaciate any help!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top