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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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