replace dash in a number sequence

W

Willy Wonka

I've got a cell that represents a sequence of numbers like p129-132 and would
like to list each number seperately: p129,p130,p131,p132.

TIA
 
G

Gary''s Student

Select the cells containing the data and run:

Sub ListMaker()
Dim n1 As Integer, n2 As Integer
Dim v As String
For Each r In Selection
s = Split(r.Value, "-")
n2 = s(1)
n1 = Right(s(0), Len(s(0)) - 1) + 1
v = s(0)
For i = n1 To n2
v = v & "," & i
Next
r.Value = v
Next
End Sub
 

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