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
 
Ideally the results would be the H21:K28 sequence.
OK, try this.
Assumption is that there is nothing in the original sheet to the right of column D, or at least nothing in columns E:G. If there is, post details of what else is on the sheet.

Original data

Excel Workbook
ABCDE
1IDSystem NameNamePredecessors
21Sys1Task10
32Sys2Task21;29
43Sys3Task32
54Sys4Task45
65Sys5Task50
76Sys6Task60
87Sys7Task75
98Sys8Task86
1028Sys9Task923;27;8
117Sys10Task1027
1223Sys11Task110
1327Sys12Task120
1429Sys13Task130
15
Data




Code (amend sheet name if required)

Rich (BB 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


Result:

Excel Workbook
ABCDE
1IDSystem NameNamePredecessors
22Sys2Task21;29
31Sys1Task10
429Sys13Task130
528Sys9Task923;27;8
68Sys8Task86
723Sys11Task110
827Sys12Task120
9
Sheet1
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Nick. I got your message. It is possible that the 23 is a string in the first variable and an integer in the second variable as you suggested. Just convert both variables to string and see if that fixes the problem. If it doesn't, I don't know. use the function CStr(variable)

eg. myValue = CStr(myValue)
 
Upvote 0
Hi Peter,
Sorry to bother you again, but there are additional rows populated to the right of column D.
I tried to retrofit myself but have been unsuccessful.
Column P is the last column used.

Thanks!

Here is the final layout:
Excel 2010
ABCDEFGHIJKLMNOP
1IDWBSUniqueIDSystem NameNameStart DateFinish DatePredecessorResourcePred Sys NamePred NamePred StartPred Finish% CompleteDiffOriginalPred
subset (2)
 
Upvote 0
1. Both the original data and the final results to have these 16 columns?

2. Column H is now the one with the semicolons?

3. Column A still the column that the semicolon list refers to? Or is it column C being "UniqueID".
If it is still column A, can you confirm that the IDs in that column are in fact unique?
 
Upvote 0
Hi Peter,
This project had been pushed back but is now back on.
Answers to your questions:
1. Both the original data and the final results to have these 16 columns? correct
2. Column H is now the one with the semicolons? correct

3. Column A still the column that the semicolon list refers to? Or is it column C being "UniqueID". Col A
If it is still column A, can you confirm that the IDs in that column are in fact unique? Are Unique

Thanks! :)
 
Upvote 0
Try
Rich (BB code):
Sub Predecessors_v2()
  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("P" & wsOld.Rows.Count).End(xlUp))
    .AutoFilter Field:=8, Criteria1:="*;*"
    On Error Resume Next
    Set scRng = .Columns(8).Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible)
    On Error GoTo 0
    .AutoFilter
    If Not scRng Is Nothing Then
      wsOld.Range("Z1").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(, 16).Copy Destination:=wsNew.Cells(nr, 1)
        wsOld.Range("Z2").Resize(UBound(Split(c.Value, ";")) + 1).Value = Application.Transpose(Split(c.Value, ";"))
        .AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsOld.Range("Z1").CurrentRegion, CopyToRange:=wsNew.Cells(nr + 1, 1), Unique:=False
        wsNew.Rows(nr + 1).Delete
        wsOld.Range("Z1").CurrentRegion.Offset(1).ClearContents
      Next c
      wsOld.Range("Z1").ClearContents
      wsNew.UsedRange.EntireColumn.AutoFit
    End If
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Peter,
Thanks for the expanded column model post above in #28, you rock!

One final twist to try and apply to original 4 column post #21: After or during the code execution, can we remove a row if the System Name Value is the same as the System Name value of the first row in the range?

twist.png


Many thanks!
 
Upvote 0

Excel 2012
ABCD
1Code produces this now:
2IdSystem NameNamePredecessors
328Sys9Task98;23;27
48Sys8Task8
523Sys9Task110
627Sys12Task120
7
8
9Can we remove the duplicate system name from the result?
10IdSystem NameNamePredecessors
1128Sys9Task98;23;27
128Sys8Task8
1327Sys12Task120
result
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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