Split Range

edwardj3

New Member
Joined
Jan 16, 2018
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Hi all,
Searched a number of forums/website but can't find a solution to my issue.

I have the following range examples. I have split the string field below to create start and end fields. Match to identify if numbers match and the difference between the two numbers.

RangestartendmatchDifference
start 409795 - End 409796 (string field)409795409796FALSE1
start 556919 - End 556931556919556931FALSE12
start 559687 - End 559723559687559723FALSE36

<colgroup><col><col span="4"></colgroup><tbody>
</tbody>

What I want is to create a macro to return the following result:


RangestartendmatchDifference
start 409795 - End 409795409795409795TRUE02 lines in total
start 409796 - End 409796409796409796TRUE0
start 556919 - End 556919556919556919TRUE012 lines in total
start 556920 - End 556920556920556920TRUE0
start 556921 - End 556921556921556921TRUE0
start 556922 - End 556922556922556922TRUE0
Through to below
start 556931 - End 556931556931556931TRUE0
start 559687 - End 559687559687559687TRUE036 lines in total
start 559688 - End 559688559688559688TRUE0
start 559689 - End 559689559689559689TRUE0
start 559690 - End 559690559690559690TRUE0
start 559691 - End 559691559691559691TRUE0
Through to below
start 559722 - End 559722559722559722TRUE0
start 559723 - End 559723559723559723TRUE0

<colgroup><col><col span="5"></colgroup><tbody>
</tbody>


Think I would need to macro to initially find where the numbers don't match, insert the required number of blank lines and then populate with increments of one until all the numbers in start and end match and then move on - probably needs some loop.

so for range start 409795 - End 409796 I would need 1 line for Start 409795 - End 409795 and another line for Start 409796 - End 409796

Hope this makes sense. Be grateful for a solution. Happy to provide further details if required.

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.
Hey edwardj3

Try the below code ... Assuming your data is in columns A to E and the output will be in the same sheet in columns H to L

Code:
Sub edwardj3()

Dim lRow As Long, Diff As Long, Start As Long
lRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

For x = 2 To lRow
Start = Cells(x, 2)
Diff = Cells(x, 5) + 1
    For y = 1 To Diff
        lRow = ActiveSheet.Range("H" & Rows.Count).End(xlUp).Row + 1
        Cells(lRow, 8) = "start " & Start & " - End " & Start
        Cells(lRow, 9) = Start
        Cells(lRow, 10) = Start
        Cells(lRow, 11) = "TRUE"
        Cells(lRow, 12) = 0
        Start = Start + 1
    Next y
Next x

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,356
Members
449,080
Latest member
Armadillos

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