How to insert number of rows in spreadsheet based on a numeric value of an cell?

GeoDog

New Member
Joined
Feb 12, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello I have a spreadsheet of well log soil/geology depth and thicknesses in feet. Each row has a distinct soil type. Below are three wells 14000000030 & 14000000031 & 14000000032. For instance the 1st well has 3 rows has the 1st soil type from LITH_AGG is Sand & Gravel from 0-55 feet. The 2nd is Clay & Sand from 55-59 feet and the 3rd is Sand & Gravel from 59-86 feet. I need to breakdown each of the depths/thicknesses in 1 foot increments. So the 1st 1st soil type from LITH_AGG is Sand & Gravel from 0-55 feet would end up being 55 rows, 1 for each 1 foot of depth. And so on
WELLIDSEQ_NUMPRIM_LITHLITH_MODLITH_AGGTOPDEPTHTHICKNESSAQTYPE
14000000030
1.00000000000​
Sand & GravelW/StonesSand & Gravel
0​
55​
55​
D
14000000030
2.00000000000​
ClaySandyClay & Sand
55​
59​
4​
D
14000000030
3.00000000000​
Gravel & SandWater BearingSand & Gravel
59​
86​
27​
D
14000000031
1.00000000000​
SandSand
0​
8​
8​
D
14000000031
2.00000000000​
ClayClay
8​
12​
4​
D
14000000031
3.00000000000​
GravelGravel
12​
69​
57​
D
14000000031
4.00000000000​
Clay & GravelDiamicton
69​
82​
13​
D
14000000031
5.00000000000​
GravelGravel
82​
91​
9​
D
14000000031
6.00000000000​
SandCoarseSand
91​
110​
19​
D
14000000032
1.00000000000​
TopsoilOrganic
0​
1​
1​
D
14000000032
2.00000000000​
ClayClay
1​
16​
15​
D
14000000032
3.00000000000​
Clay & GravelDiamicton
16​
26​
10​
D
14000000032
4.00000000000​
Sand & GravelSand & Gravel
26​
55​
29​
D
14000000032
5.00000000000​
Clay & GravelDiamicton
55​
94​
39​
D
14000000032
6.00000000000​
SandMediumSand
94​
110​
16​
D

Below is a typical well log similar to the above

WELLIDSEQ_NUMPRIM_LITHLITH_MODLITH_AGGTOPDEPTHTHICKNESSAQTYPECLASSEFFECTMAQTYPECOLOR
14000000033
1.00000000000​
TopsoilOrganic
0​
1​
1​
DNA
0.00000000000​
NA
14000000033
2.00000000000​
SandSand
1​
20​
19​
DAQ
0.00000000000​
AQ
14000000033
3.00000000000​
Sand & GravelW/ClayDiamicton
18​
24​
6​
DAQ
1.00000000000​
MAQ
14000000033
4.00000000000​
GravelCoarseGravel
24​
30​
6​
DAQ
0.00000000000​
AQ

This is what I was hoping on getting of 1 row per foot depth
WELLIDSEQ_NUMPRIM_LITHLITH_MODLITH_AGGTOPDEPTHTHICKNESSTOP1FTDEPTH1FTTHICKNESS1FTAQTYPE
14000000033
1.00000000000​
TopsoilOrganic
0​
1​
1​
0​
1​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
1​
2​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
2​
3​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
3​
4​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
4​
5​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
5​
6​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
6​
7​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
7​
8​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
8​
9​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
9​
10​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
10​
11​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
11​
12​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
12​
13​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
13​
14​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
14​
15​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
15​
16​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
16​
17​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
17​
18​
1​
D
14000000033
2.00000000000​
SandSand
1​
20​
19​
18​
19​
1​
D
14000000033
3.00000000000​
Sand & GravelW/ClayDiamicton
20​
24​
4​
19​
20​
1​
D
14000000033
3.00000000000​
Sand & GravelW/ClayDiamicton
20​
24​
4​
20​
21​
1​
D
14000000033
3.00000000000​
Sand & GravelW/ClayDiamicton
20​
24​
4​
21​
22​
1​
D
14000000033
3.00000000000​
Sand & GravelW/ClayDiamicton
20​
24​
4​
22​
23​
1​
D
14000000033
3.00000000000​
Sand & GravelW/ClayDiamicton
20​
24​
4​
23​
24​
1​
D
14000000033
4.00000000000​
GravelCoarseGravel
24​
30​
6​
24​
25​
1​
D
14000000033
4.00000000000​
GravelCoarseGravel
24​
30​
6​
25​
26​
1​
D
14000000033
4.00000000000​
GravelCoarseGravel
24​
30​
6​
25​
26​
1​
D
14000000033
4.00000000000​
GravelCoarseGravel
24​
30​
6​
27​
28​
1​
D
14000000033
4.00000000000​
GravelCoarseGravel
24​
30​
6​
28​
29​
1​
D
14000000033
4.00000000000​
GravelCoarseGravel
24​
30​
6​
29​
30​
1​
D
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try This
VBA Code:
Sub Num_Rw_Cell_Val1()
'Quoted from Fluff VBA script Code :https://www.mrexcel.com/board/threads/transpose-every-x-amount-of-columns-to-rows-keeping-cell-of-first-column-on-each-row.1157009/post-5610934
Dim Rng As Range

Dim ArrVal As Variant, CompArr As Variant

Set Rng = Sheets("Sheet1").Range("A1").CurrentRegion
ArrVal = Rng.CurrentRegion.Value2
SumCL8 = Application.Sum(Rng.Columns(8))
ReDim CopmArr(1 To SumCL8 + 10, 1 To Rng.Columns.Count)
For r = 2 To UBound(ArrVal)
    For c = 8 To 8
        If IsNumeric(ArrVal(r, c)) = True Then
            NumRw = ArrVal(r, c)
            For rw = 1 To NumRw
            nr = nr + 1
                For cl = 1 To 9
                CopmArr(nr, cl) = ArrVal(r, c + cl - 8)
                Next
            Next
        End If
    Next
Next

Range("A25").Resize(nr, Rng.Columns.Count) = CopmArr
End Sub

Some Rows of
Book1
ABCDEFGHI
1WELLIDSEQ_NUMPRIM_LITHLITH_MODLITH_AGGTOPDEPTHTHICKNESSAQTYPE
2140000000301Sand & GravelW/StonesSand & Gravel05555D
3140000000302ClaySandyClay & Sand55594D
4140000000303Gravel & SandWater BearingSand & Gravel598627D
5140000000311SandSand088D
6140000000312ClayClay8124D
7140000000313GravelGravel126957D
8140000000314Clay & GravelDiamicton698213D
9140000000315GravelGravel82919D
10140000000316SandCoarseSand9111019D
11140000000321TopsoilOrganic011D
12140000000322ClayClay11615D
13140000000323Clay & GravelDiamicton162610D
14140000000324Sand & GravelSand & Gravel265529D
15140000000325Clay & GravelDiamicton559439D
16140000000326SandMediumSand9411016D
17
18
19
20
21
22
23
24
25140000000301Sand & GravelW/StonesSand & Gravel05555D
26140000000301Sand & GravelW/StonesSand & Gravel05555D
27140000000301Sand & GravelW/StonesSand & Gravel05555D
28140000000301Sand & GravelW/StonesSand & Gravel05555D
29140000000301Sand & GravelW/StonesSand & Gravel05555D
30140000000301Sand & GravelW/StonesSand & Gravel05555D
31140000000301Sand & GravelW/StonesSand & Gravel05555D
32140000000301Sand & GravelW/StonesSand & Gravel05555D
33140000000301Sand & GravelW/StonesSand & Gravel05555D
34140000000301Sand & GravelW/StonesSand & Gravel05555D
35140000000301Sand & GravelW/StonesSand & Gravel05555D
36140000000301Sand & GravelW/StonesSand & Gravel05555D
37140000000301Sand & GravelW/StonesSand & Gravel05555D
38140000000301Sand & GravelW/StonesSand & Gravel05555D
39140000000301Sand & GravelW/StonesSand & Gravel05555D
40140000000301Sand & GravelW/StonesSand & Gravel05555D
41140000000301Sand & GravelW/StonesSand & Gravel05555D
Sheet1
 
Last edited:
Upvote 0
Welcome to the MrExcel board!

I'm hoping that you have some typos in your sample data and expected results.
A few examples:
  1. Sand goes from 1 to 20 in the data but the deepest sand in your results is 18 to 19
  2. Sand & Gravel starts at 18 in the data but starts at 19 in the results
  3. Sand & Gravel has thickness of 6 in the data but 4 in the results.

This would be my interpretation of what you want.

VBA Code:
Sub LayerByFoot()
  Dim a As Variant, b As Variant
  Dim i As Long, k As Long, r As Long, c As Long, ubb2 As Long
  
  a = Range("A2", Range("I" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To Rows.Count, 1 To 12)
  ubb2 = UBound(b, 2)
  For i = 1 To UBound(a)
    r = 0
    For r = a(i, 6) To a(i, 7) - 1
      k = k + 1
      For c = 1 To 8
        b(k, c) = a(i, c)
      Next c
      b(k, 9) = r
      b(k, 10) = r + 1
      b(k, 11) = 1
      b(k, 12) = a(i, 9)
    Next r
  Next i
  Range("A" & Rows.Count).End(xlUp).Offset(3).Resize(k, ubb2).Value = b
End Sub

Here is my sample data with results below.

GeoDog.xlsm
ABCDEFGHIJKLM
1WELLIDSEQ_NUMPRIM_LITHLITH_MODLITH_AGGTOPDEPTHTHICKNESSAQTYPECLASSEFFECTMAQTYPECOLOR
2140000000331TopsoilOrganic011DNA0NA
3140000000332SandSand12019DAQ0AQ
4140000000333Sand & GravelW/ClayDiamicton18246DAQ1MAQ
5140000000334GravelCoarseGravel24306DAQ0AQ
6
7
8140000000331TopsoilOrganic011011D
9140000000332SandSand12019121D
10140000000332SandSand12019231D
11140000000332SandSand12019341D
12140000000332SandSand12019451D
13140000000332SandSand12019561D
14140000000332SandSand12019671D
15140000000332SandSand12019781D
16140000000332SandSand12019891D
17140000000332SandSand120199101D
18140000000332SandSand1201910111D
19140000000332SandSand1201911121D
20140000000332SandSand1201912131D
21140000000332SandSand1201913141D
22140000000332SandSand1201914151D
23140000000332SandSand1201915161D
24140000000332SandSand1201916171D
25140000000332SandSand1201917181D
26140000000332SandSand1201918191D
27140000000332SandSand1201919201D
28140000000333Sand & GravelW/ClayDiamicton1824618191D
29140000000333Sand & GravelW/ClayDiamicton1824619201D
30140000000333Sand & GravelW/ClayDiamicton1824620211D
31140000000333Sand & GravelW/ClayDiamicton1824621221D
32140000000333Sand & GravelW/ClayDiamicton1824622231D
33140000000333Sand & GravelW/ClayDiamicton1824623241D
34140000000334GravelCoarseGravel2430624251D
35140000000334GravelCoarseGravel2430625261D
36140000000334GravelCoarseGravel2430626271D
37140000000334GravelCoarseGravel2430627281D
38140000000334GravelCoarseGravel2430628291D
39140000000334GravelCoarseGravel2430629301D
Sheet1
 
Upvote 0
Solution
Yes you were right I did have some typos, sorry. Wow this worked the 1st time I tried it. Thank you so much. One thing is that it overwrote the 2 of the existing columns that have important data. Would it be possible to have it write to 2 new fields at the end of the table in columns N and O, like TOP1FTI DEPTH1FTI? Would it be possible to have it write the data to a new sheet?
Again, thank you so much.
 
Upvote 0
Would it be possible to have it write the data to a new sheet?
Like this?

VBA Code:
Sub LayerByFoot_v2()
  Dim a As Variant, b As Variant
  Dim i As Long, k As Long, r As Long, c As Long, ubb2 As Long
  
  a = Range("A2", Range("I" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To Rows.Count, 1 To 12)
  ubb2 = UBound(b, 2)
  For i = 1 To UBound(a)
    r = 0
    For r = a(i, 6) To a(i, 7) - 1
      k = k + 1
      For c = 1 To 8
        b(k, c) = a(i, c)
      Next c
      b(k, 9) = r
      b(k, 10) = r + 1
      b(k, 11) = 1
      b(k, 12) = a(i, 9)
    Next r
  Next i
  With Sheets.Add(After:=ActiveSheet).Range("A2").Resize(k, ubb2)
    .Value = b
    .Rows(0).Value = Array("WELLID", "SEQ_NUM", "PRIM_LITH", "LITH_MOD", "LITH_AGG", "TOP", "DEPTH", "THICKNESS", "TOP1FT", "DEPTH1FT", "THICKNESS1FT", "AQTYPE")
    .EntireColumn.AutoFit
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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