Copy data in between 2 cells

ceclay

Board Regular
Joined
Dec 4, 2019
Messages
58
Office Version
  1. 2016
Platform
  1. Windows
Hi,
Would like to ask help. I have this 1 column data below:
Golf Data.xlsx
A
1Performance Win Only
2Mickelson, Jake
323
4n
5Si Woo Jun
623
7n
8Steele, Brick
923
10n
11Dahmen, Nina
1229
13n
14Garcia, Srick
1529
16n
17Spieth, Michael
1831
19n
20Varner , Franco
2131
22n
23Lowry, Nica
2434
25n
26Grillo, Emiliano
27Opens:
28200908 1211
29Suspends:
30200910 1600
31Closes:
32Straight Forecast
331. Garcia, Sergio/2. Mickelson, Phil
34541
35n
361. Mickelson, Phil/2. Garcia, Sergio
37541
38n
391. Mickelson, Phil/2. Steele, Brendan
40541
41n
421. Steele, Brendan/2. Mickelson, Phil
43541
44n
451. Lowry, Shane/2. Mickelson, Phil
46601
47n
48Opens:
49200908 1211
50Suspends:
51200910 1600
52Closes:
Sheet4


I would like to copy data in between "Performance Win Only" and "Opens:" to make it like below:
Golf Data.xlsx
FGHIJ
1
2Mickelson, JakeMickelson, Jake23n
323Si Woo Jun23n
4nSteele, Brick23n
5Si Woo JunDahmen, Nina29n
623Garcia, Srick29n
7nSpieth, Michael31n
8Steele, BrickVarner , Franco31n
923Lowry, Nica34n
10n
11Dahmen, Nina
1229
13n
14Garcia, Srick
1529
16n
17Spieth, Michael
1831
19n
20Varner , Franco
2131
22n
23Lowry, Nica
2434
25n
Sheet4


Also, copy data in between "Straight Forecast" and "Opens" to make it like below:
Golf Data.xlsx
LMNO
1
21. Garcia, Sergio/2. Mickelson, Phil1. Garcia, Sergio/2. Mickelson, Phil541n
35411. Mickelson, Phil/2. Garcia, Sergio541n
4n1. Mickelson, Phil/2. Steele, Brendan541n
51. Mickelson, Phil/2. Garcia, Sergio1. Steele, Brendan/2. Mickelson, Phil541n
65411. Lowry, Shane/2. Mickelson, Phil601n
7n
81. Mickelson, Phil/2. Steele, Brendan
9541
10n
111. Steele, Brendan/2. Mickelson, Phil
12541
13n
141. Lowry, Shane/2. Mickelson, Phil
15601
16n
Sheet4
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
How about
VBA Code:
Sub ceclay()
   Dim Ary(1 To 2) As Variant, Nary As Variant
   Dim Ar As Areas
   Dim r As Long, i As Long, nr As Long
   
   With Range("A:A")
      .Replace "Opens:", "=A1", xlWhole, , False, , False, False
      .Replace "Closes:", "=xxx", xlWhole, , False, , False, False
      Set Ar = .SpecialCells(xlConstants).Areas
      .Replace "=A1", "Opens:", xlWhole, , False, , False, False
      .Replace "=xxx", "Closes:", xlWhole, , False, , False, False
   End With
   Ary(1) = Ar(1).Value2
   Ary(2) = Ar(3).Value2
   Range("F1").Resize(UBound(Ary(1))).Value = Ary(1)
   Range("L1").Resize(UBound(Ary(2))).Value = Ary(2)
   For i = 1 To 2
      ReDim Nary(1 To UBound(Ary(i)), 1 To 3)
      For r = 2 To UBound(Ary(i)) - 1 Step 3
         nr = nr + 1
         Nary(nr, 1) = Ary(i)(r, 1)
         Nary(nr, 2) = Ary(i)(r + 1, 1)
         Nary(nr, 3) = Ary(i)(r + 2, 1)
      Next r
      If i = 1 Then
         Range("H2").Resize(nr, 3).Value = Nary
      Else
         Range("M2").Resize(nr, 3).Value = Nary
      End If
      nr = 0
   Next i
End Sub
 
Upvote 0
Another approach:

VBA Code:
Sub Extract_Data()
  Dim rStart As Range, rEnd As Range
  Dim r As Long
  
  Set rStart = Columns("A").Find(What:="Performance Win Only", LookAt:=xlWhole, MatchCase:=False)
  If Not rStart Is Nothing Then
    Set rEnd = Columns("A").Find(What:="Opens:", After:=rStart, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=False)
    If Not rEnd Is Nothing Then
      r = rStart.Row + 1
      Do While r + 2 < rEnd.Row
        Range("H" & Rows.Count).End(xlUp).Offset(1).Resize(, 3).Value = Application.Transpose(Range("A" & r).Resize(3).Value)
        r = r + 3
      Loop
    End If
  End If
  
  Set rStart = Columns("A").Find(What:="Straight Forecast", LookAt:=xlWhole, MatchCase:=False)
  If Not rStart Is Nothing Then
    Set rEnd = Columns("A").Find(What:="Opens:", After:=rStart, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=False)
    If Not rEnd Is Nothing Then
      r = rStart.Row + 1
      Do While r + 2 < rEnd.Row
        Range("M" & Rows.Count).End(xlUp).Offset(1).Resize(, 3).Value = Application.Transpose(Range("A" & r).Resize(3).Value)
        r = r + 3
      Loop
    End If
  End If
End Sub
 
Upvote 0
You're welcome. Glad we could help. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,186
Members
449,071
Latest member
cdnMech

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