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
[TABLE="width: 174"]
<colgroup><col span="3"></colgroup><tbody>[TR]
[TD]Company [/TD]
[TD]From[/TD]
[TD]To[/TD]
[/TR]
[TR]
[TD]1000[/TD]
[TD]1000[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1039[/TD]
[TD]1039[/TD]
[TD]1041[/TD]
[/TR]
[TR]
[TD]1040[/TD]
[TD]1043[/TD]
[TD]1044[/TD]
[/TR]
[TR]
[TD]1041[/TD]
[TD]1044[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1043[/TD]
[TD]1046[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1044[/TD]
[TD]1053[/TD]
[TD]1056[/TD]
[/TR]
[TR]
[TD]1046[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1053[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1054[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1055[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1056[/TD]
[TD] [/TD]
[TD]


[/TD]
[/TR]
</tbody>[/TABLE]
Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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,226,730
Messages
6,192,708
Members
453,748
Latest member
akhtarf3

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