Generate subset table from Master table

Nick30075

New Member
Joined
May 16, 2013
Messages
26
I have a table that looks like this:
Need Col D values that have ";" present to be parsed out to create and new worksheet with the results looking like the output below.

I've looked & tried but is beyond my level at this time. Any & all help is greatly appreciated!
:banghead:


Excel 2010
ABCD
1IDSystem NameNamePredecessors
21Sys1Task10
32Sys2Task21
43Sys3Task32
54Sys4Task45
65Sys5Task50
76Sys6Task60
87Sys7Task75
98Sys8Task86
1028Sys9Task923;27;8
117Sys10Task1027
1223Sys11Task110
1327Sys12Task120
Sheet4


Need output like this in a new worksheet:

Excel 2010
ABCD
1New sheet results
2IDSystem NameNamePredecessors
328Sys9Task923;27;8
423Sys11Task110
527Sys12Task120
68Sys8Task86
Sheet1
 
I'm no longer sure about your columns.

Please confirm, for the original data sheet ..
- The extent of all columns used (previously was A:P)
- The Predecessors column (was H)
- The Id column (A)
- System Name column (B)

Is any repetition of the System name always a repeat of the value in the first row of the group like your sample above? That is, the row with the semicolons?
 
Last edited:
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
see answers below:

- The extent of all columns used = A:D
- The Predecessors column = D
- The Id column = A
- System Name column = B

Is any repetition of the System name always a repeat of the value in the first row of the group like your sample above? Correct
That is, the row with the semicolons? Correct

After or during the code execution, remove a row if the System Name Value is the same as the System Name value of the first row in the range?
If all System Names in the range are the same, delete the entire range

Thanks!

This is the original "4" column code from post 21 above:
Code:
Sub Predecessors()
  Dim scRng As Range, c As Range
  Dim nr As Long
  Dim wsOld As Worksheet, wsNew As Worksheet
  
  Set wsOld = Sheets("Data")  '<- Change to match your sheet name
  Application.ScreenUpdating = False
  With wsOld.Range("A1", wsOld.Range("D" & wsOld.Rows.Count).End(xlUp))
    .AutoFilter Field:=4, Criteria1:="*;*"
    On Error Resume Next
    Set scRng = .Columns(4).Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible)
    On Error GoTo 0
    .AutoFilter
    If Not scRng Is Nothing Then
      wsOld.Range("F1").Value = wsOld.Range("A1").Value
      Set wsNew = Sheets.Add(After:=wsOld)
      .Rows(1).Copy Destination:=wsNew.Range("A1")
      For Each c In scRng
        nr = wsNew.Range("A" & wsNew.Rows.Count).End(xlUp).Row + 1
        c.EntireRow.Resize(, 4).Copy Destination:=wsNew.Cells(nr, 1)
        wsOld.Range("F2").Resize(UBound(Split(c.Value, ";")) + 1).Value = Application.Transpose(Split(c.Value, ";"))
        .AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsOld.Range("F1").CurrentRegion, CopyToRange:=wsNew.Cells(nr + 1, 1), Unique:=False
        wsNew.Rows(nr + 1).Delete
        wsOld.Range("F1").CurrentRegion.Offset(1).ClearContents
      Next c
      wsOld.Range("F1").ClearContents
      wsNew.Columns("A:D").AutoFit
    End If
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
see answers below:

- The extent of all columns used = A:D
- The Predecessors column = D
- The Id column = A
- System Name column = B

Is any repetition of the System name always a repeat of the value in the first row of the group like your sample above? Correct
That is, the row with the semicolons? Correct
Try

Rich (BB code):
Sub Predecessors_v3()
  Dim scRng As Range, c As Range
  Dim nr As Long
  Dim wsOld As Worksheet, wsNew As Worksheet
  
  Const f As String = "=AND(OR(A2={#}),B2<>""@"")"
  
  Set wsOld = Sheets("Data")  '<- Change to match your sheet name
  Application.ScreenUpdating = False
  With wsOld.Range("A1", wsOld.Range("D" & wsOld.Rows.Count).End(xlUp))
    .AutoFilter Field:=4, Criteria1:="*;*"
    On Error Resume Next
    Set scRng = .Columns(4).Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible)
    On Error GoTo 0
    .AutoFilter
    If Not scRng Is Nothing Then
      Set wsNew = Sheets.Add(After:=wsOld)
      .Rows(1).Copy Destination:=wsNew.Range("A1")
      For Each c In scRng
        wsOld.Range("Z2").Formula = Replace(Replace(f, "#", Replace(c.Value, ";", ",")), "@", .Range("B" & c.Row).Value)
        nr = wsNew.Range("A" & wsNew.Rows.Count).End(xlUp).Row + 1
        c.EntireRow.Resize(, 4).Copy Destination:=wsNew.Cells(nr, 1)
        .AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsOld.Range("Z1:Z2"), CopyToRange:=wsNew.Cells(nr + 1, 1), Unique:=False
        wsNew.Rows(nr + 1).Delete
      Next c
      wsOld.Range("Z2").ClearContents
      wsNew.UsedRange.EntireColumn.AutoFit
    End If
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Peter,
Works great, is it possible to remove the row with the semi colons also if all System Names in the range are the same? (delete the entire range)
In the example below, rows 2 thru 14 would be deleted.

Thanks!



Excel 2010
ABCD
1IDSystem NameNamePredecessors
227150uS Water SystemExecute FAT Protocol23;24;25;26
337150uS Water SystemExecute SAT Protocol33;34;35;36
447150uS Water SystemExecute (IOQ) Protocol43;44;45;46
589PURIFIED WATERExecute FAT Protocol85;88
699PURIFIED WATERExecute SAT Protocol95;96;97;98
7122PURIFIED WATERReview and release PQ1 test results120;121
8131PURIFIED WATERReview and release PQ1 test results129;130
9140PURIFIED WATERReview and release PQ1 test results138;139
10171PURIFIED WATER - Loop 6 & 7Review and release PQ1 test results169;170
11180PURIFIED WATER - Loop 6 & 7Review and release PQ2 test results178;179
12189PURIFIED WATER - Loop 6 & 7Review and release PQ3 test results187;188
13262HOT PROCESS WATERExecute FAT Protocol258;259;260;261
14272HOT PROCESS WATERExecute SAT Protocol268;269;270;271
15367TANK FARMResolve Action Items434;424
16424Solvent Supply SystemExecute SAT Protocol
17434Solvent Supply SystemExecute (IOQ) Protocol
18368TANK FARMClose CR438;428
19428Solvent Supply SystemRoute SAT Protocol for post-execution approval427
20438Solvent Supply SystemRoute (IOQ) Protocol for post-execution approval437
Sheet7
 
Upvote 0
Does adding this blue line of code where indicated achieve what you want?
Rich (BB code):
  wsNew.Rows(nr + 1).Delete
  If wsNew.Range("A" & wsNew.Rows.Count).End(xlUp).Row = nr Then wsNew.Rows(nr).Delete
Next c
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,637
Latest member
Ezio2866

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