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!
:oops:


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
 
Hi WarPigl3t,
We are all but there, thanks for everything so far!

CopyPaste bolded below is generating a Compile error: syntax error.

Code:
Sub pastePredecessorRows(dataSheet, outputSheet, columnSearch, firstRow, lastRow, pasteRow, myValue, columnID)
     mySplit = Split(myValue, ";")
     For Each element In mySplit
          r = firstRow
          myValue = Sheets(dataSheet).Range(columnID & r).Value
          Do Until r > lastRow Or element = myValue
               r = r + 1
               myValue = Sheets(dataSheet).Range(columnID & r).Value
          Loop
          If element = myValue Then
               [U][/U][B]CopyPaste(dataSheet, outputSheet, r, pasteRow)[/B]
               pasteRow = pasteRow + 1
          End If
     Next element
End Sub
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
In regards to the compile error on this line.

CopyPaste(dataSheet, outputSheet, r, pasteRow)

My bad. That's not how you call a subroutine and CopyPaste is a subroutine. That's how you call a function. Here's how you call a subroutine.

Call CopyPaste(dataSheet, outputSheet, r, pasteRow)

Haha I know. such a simple solution.
 
Upvote 0
WarPigl3t,
Seems the pastePredecessorRows sub is not pasting anything.

Can see the elements cycle thru the myvalue splits but nothing ever pastes to the new sheet
Code:
  : element : "23" : Variant/String

When MyValue=23 the loop kicks in and changes MyValue to the next element (27) without pasting to new sheet.

Thanks!
 
Upvote 0
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!
:oops:


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


Some clarification questions:

1. Will there be only one cell in column D that contains semicolons? If not, does each set get parsed out to a separate new sheet, or do they all go into columns A:D of just a single new sheet, something else?

2. If the semicolon list in your sample was "23;27;7" then what row(s) would get pulled to the new sheet given that you have two rows with ID = 7 and those rows contain different data?

3. Does the order of the rows in the new worksheet matter? That is, would it matter for your example if the result sheet was in the ID order: 8,23,27,28 or 28,8,23,27?
 
Upvote 0
After reviewing the code again, I am unsure why it is never entering the if statement when element = myValue. Sorry.

Can you tell me what element and myValue are equal to when the code exits the loop right before it hits the if statement?
 
Last edited:
Upvote 0
Responses to Questions:
1. Will there be only one cell in column D that contains semicolons? If not, does each set get parsed out to a separate new sheet, or do they all go into columns A:D of just a single new sheet, something else?
No there can be multiple instances of multi ";" delimited values in col D.
Parsed into the A:D columns in the single new worksheetsheet


2. If the semicolon list in your sample was "23;27;7" then what row(s) would get pulled to the new sheet given that you have two rows with ID = 7 and those rows contain different data?
Would pull the original row containing the semi colon values in Col D
Would pull the row that has 23 in col A
Would pull the row that has 27 in col A
Would pull the row that has 7 in col A

3. Does the order of the rows in the new worksheet matter? That is, would it matter for your example if the result sheet was in the ID order: 8,23,27,28 or 28,8,23,27?
Order will not matter


The sequence is this:
Find the values in Col D that have semi-colons present
For Col D cells that contain ; copy the initial row where the occurance is present into a new worksheet then
copy the rows of the values contained in the ";" delimited cell to the new worksheet

Thanks!
 
Upvote 0
Okay that didn't answer my question so I'll assume you don't know how to retrieve values from variables and let Peter help you from here.
 
Upvote 0
Responses to Questions:

2. If the semicolon list in your sample was "23;27;7" then what row(s) would get pulled to the new sheet given that you have two rows with ID = 7 and those rows contain different data?

Would pull the row that has 7 in col A


3. Does the order of the rows in the new worksheet matter? That is, would it matter for your example if the result sheet was in the ID order: 8,23,27,28 or 28,8,23,27?
Order will not matter

The red part above is written in the singular so does not address my question. There were two rows in the original data with 7 in col A. Do they both get pulled to the new sheet? If not, which one & why?



In relation to "order does not matter", if the data was as I have shown in columns A:D below, which results in columns H:K would suffice?

H1:K8
That is results in any order.
Easiest to achieve.


H11:K18
Each 'set' of results together, but in any order.
Next easiest.

H21:K28
Semicolon line first, followed by related items in any order.
Least easy.



Colours are just to make identification easier while testing.

Excel Workbook
ABCDEFGHIJK
1IDSystem NameNamePredecessorsIDSystem NameNamePredecessors
21Sys1Task101Sys1Task10
32Sys2Task21;292Sys2Task21;29
43Sys3Task328Sys8Task86
54Sys4Task4528Sys9Task923;27;8
65Sys5Task5023Sys11Task110
76Sys6Task6027Sys12Task120
87Sys7Task7529Sys13Task130
98Sys8Task86
1028Sys9Task923;27;8
117Sys10Task1027IDSystem NameNamePredecessors
1223Sys11Task1101Sys1Task10
1327Sys12Task1202Sys2Task21;29
1429Sys13Task13029Sys13Task130
158Sys8Task86
1628Sys9Task923;27;8
1723Sys11Task110
1827Sys12Task120
19
20
21IDSystem NameNamePredecessors
222Sys2Task21;29
231Sys1Task10
2429Sys13Task130
2528Sys9Task923;27;8
268Sys8Task86
2723Sys11Task110
2827Sys12Task120
29
Sheet1
 
Upvote 0
Hi Peter,
Apologies, the occurance of '7' twice in col A is an error (dummy data).
The Column A 'Id' value will contain unique values, no duplicates.

Ideally the results would be the H21:K28 sequence.
However as it is the most complex design the H11:K18 & H1:K8 will be more than adequate.
So whatever your time allows for I'll be very appreciative of the effort!

Many Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,249
Members
449,093
Latest member
Vincent Khandagale

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