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
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,122,576
Messages
5,596,987
Members
414,115
Latest member
SFUser

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
Top