ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   replace dash in a number sequence (https://www.excelbanter.com/excel-worksheet-functions/176649-replace-dash-number-sequence.html)

Willy Wonka

replace dash in a number sequence
 
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



Gary''s Student

replace dash in a number sequence
 
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
--
Gary''s Student - gsnu200769


"Willy Wonka" wrote:

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




All times are GMT +1. The time now is 01:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com