Generate From and To Range from List of Numbers

mamin123

New Member
Joined
Jun 10, 2008
Messages
12
Hi
I like to generate Range FROM and TO Values in Column B and C from Column C as shown in below. What will be formula which will achieve same ?
Basically I want to create range for all Continuous values and create range in Column B/C

Col A Col B ColC
Company FromTo
10001000
103910391041
104010431044
10411044
10431046
104410531056
1046
1053
1054
1055
1056



<colgroup><col span="3"></colgroup><tbody>
</tbody>
Thanks
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try this
Code:
Sub t()
With ActiveSheet
    .Range("B2") = .Range("A2").Value
    For Each c In Range("A3", .Cells(Rows.Count, 1).End(xlUp))
        If c.Value - c.Offset(-1).Value > 1 Then
            .Cells(Rows.Count, 2).End(xlUp)(2) = c.Value
        ElseIf c.Value - c.Offset(-1).Value = 1 And (c.Offset(1).Value - c.Value > 1 Or c.Offset(1) = "") Then
            .Cells(Rows.Count, 2).End(xlUp).Offset(, 1) = c.Value
        End If
    Next
End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top