Splitting big value into smaller values

mythcif

New Member
Joined
Apr 22, 2014
Messages
2
Dear All

I have some spreadsheets containing substantial rows of data, basically 3 columns as this:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Sample[/TD]
[TD]Start[/TD]
[TD]End[/TD]
[TD]Difference (End-Start)[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]1500
[/TD]
[TD]1600
[/TD]
[TD]100
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]1200
[/TD]
[TD]1260
[/TD]
[TD]60
[/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]960
[/TD]
[TD]1020
[/TD]
[TD]60
[/TD]
[/TR]
[TR]
[TD]D[/TD]
[TD]900[/TD]
[TD]920[/TD]
[TD]20[/TD]
[/TR]
</tbody>[/TABLE]

And what i want to obtain is different rows of data such as every row has the same difference (20 in this case, without changing the first column), like the following (never mind the colors, they are only to make my point clear):

[TABLE="width: 500"]
<tbody>[TR]
[TD]Sample[/TD]
[TD]Start[/TD]
[TD]End[/TD]
[TD]Difference (End-Start)[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]1500
[/TD]
[TD]1520
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]1520
[/TD]
[TD]1540
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]1540
[/TD]
[TD]1560
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]1560
[/TD]
[TD]1580
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]1580
[/TD]
[TD]1600
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]1200
[/TD]
[TD]1220
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]1220
[/TD]
[TD]1240
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]1220
[/TD]
[TD]1260
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]960
[/TD]
[TD]980
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]980
[/TD]
[TD]1000
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]1000
[/TD]
[TD]1020
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]D[/TD]
[TD]900[/TD]
[TD]920[/TD]
[TD]20[/TD]
[/TR]
</tbody>[/TABLE]

We can also think about splitting only one certain number into 20's, like in the case of samples B and C above, because I have already split the data into separate sheets based on their "difference" value, using the help in this link:
http://www.mrexcel.com/forum/excel-questions/396069-copy-new-worksheets.html

Do you think it is doable?

Many thanks in advance,

Best,

m.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Excel 2012
ABCDEFGHIJ
1SampleStartEndDifference (End-Start)SampleStartEndDifference(End-Start)
2A15001600100A1500152020
3B1200126060A1520154020
4C960102060A1540156020
5D90092020A1560158020
6A1580160020
7B1200122020
8B1220124020
9B1240126020
10C96098020
11C980100020
12C1000102020
13D90092020
14
15
16
Sheet3







Code:
Sub SSSSS()
Dim c00      As Variant
Dim fData()  As Variant
Dim UBfDa    As Integer
Dim iRow     As Integer
Dim iCount   As Integer
Dim iDiff    As Integer
Dim iC       As Integer
Const iScale As Integer = 20


iRow = Range("D" & Rows.Count).End(xlUp).Row


' original array
c00 = Range("A2:D" & iRow)


' ubound of new array
UBfDa = Evaluate("SUM((D2:D" & iRow & ")/" & iScale & ")")
ReDim fData(1 To UBfDa, 1 To 4)


UBfDa = 1


For iCount = 1 To UBound(c00, 1)
    iDiff = c00(iCount, 4) / iScale
        For iC = 1 To iDiff
            fData(UBfDa, 1) = c00(iCount, 1)
            fData(UBfDa, 2) = c00(iCount, 2) + ((iC - 1) * iScale)
            fData(UBfDa, 3) = fData(UBfDa, 2) + iScale
            fData(UBfDa, 4) = iScale
            UBfDa = UBfDa + 1
        Next
Next
Range("G1:J1") = Array("Sample", "Start", "End", "Difference(End-Start)")
Range("G2").Resize(UBound(fData, 1), UBound(fData, 2)) = fData
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,052
Members
452,542
Latest member
Bricklin

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