Create Parent Child from legacy data

arosyid

New Member
Joined
Oct 9, 2017
Messages
4
Hi MrExcel.

I would like to ask abaout data processing using macro instead manual process.
because it's repetition task.

please someone help me to solve this case using macro.

Thanks in advanced.

MyuaHRc.png
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
for additional information.

by running the macro, i will get the expected result.
1. create new two coulomb.
2. read data hierarchy from existing data (coulomb item ), and paste the name in the line manager.
3. create new information, manager and staff depend on the name has sub-ordinate employee or not.

Thanks.
 
Upvote 0
Welcome to Mr Excel

If a solution using formulas is acceptable, maybe something like this

A
B
C
D
E
F
G
H
1
Item​
Name​
Item​
Line manager​
Name​
Position​
2
1​
adry​
1​
top manager​
adry​
manager​
3
1.1​
diana​
1.1​
adry​
diana​
staff​
4
1.2​
john​
1.2​
adry​
john​
manager​
5
1.2.1​
joshua​
1.2.1​
john​
joshua​
staff​
6
1.2.2​
gabriel​
1.2.2​
john​
gabriel​
manager​
7
1.2.2.1​
kevin​
1.2.2.1​
gabriel​
kevin​
staff​
8
1.2.2.2​
jihan​
1.2.2.2​
gabriel​
jihan​
staff​
9
1.2.2.3​
sary​
1.2.2.3​
gabriel​
sary​
staff​
10
1.2.3​
bob​
1.2.3​
john​
bob​
staff​
11
1.2.4​
tesla​
1.2.4​
john​
tesla​
staff​
12
2​
bush​
2​
top manager​
bush​
manager​
13
2.1​
george​
2.1​
bush​
george​
staff​
14
2.2​
olof​
2.2​
bush​
olof​
manager​
15
2.2.1​
steven​
2.2.1​
olof​
steven​
staff​
16
2.2.2​
kent​
2.2.2​
olof​
kent​
staff​


Columns E and G are identical to A and B respectively. So you can either copy/paste or use formulas

in E2 copied down
=A2

in G2 copied down
=B2

Results
Formula in F2 copied down
=IFERROR(INDEX(B:B,MATCH(LEFT(A2,SEARCH("#",SUBSTITUTE(A2,".","#",LEN(A2)-LEN(SUBSTITUTE(A2,".",""))))-1),A:A,0)),"top manager")

Formula in H2 copied down
=IF(COUNTIF(A$2:A$1000,A2&"*")>1,"manager","staff")

Hope this helps

M.
 
Upvote 0
Dear marcelo,

Thanks for your help,
i've try and it's work for H2 formula.

but, i've problem with F2 coloumb.
is there any mistakes from copied formula?

Thanks in advanced.
AR.

jEl1swJ.png
 
Upvote 0
The values in column A must be texts, not numbers, for the formula to work.

Either format column A as text and re-enter the Items or put an apostrophe before each item like
Type in A2
'1
'1.1
'1.2
...

M.
 
Last edited:
Upvote 0
Another option if you are happy to have the item number of the "top managers" with a "." at the end like below.
Since you appear to have formal tables I have used structured references in my formulas. If the left hand table is not called "Table1" then change that in the column E & column G formulas.
Table1 can be left with the mixture of numerical & text values in column A.


Book1
ABCDEFGH
1itemNameitemline managerNameposition
21adry1.top manageradrymanager
31.1diana1.1adrydianastaff
41.2john1.2adryjohnmanager
51.2.1jhosua1.2.1johnjhosuastaff
61.2.2gabriel1.2.2johngabrielmanager
71.2.2.1kevin1.2.2.1gabrielkevinstaff
81.2.2.2jihan1.2.2.2gabrieljihanstaff
91.2.2.3sary1.2.2.3gabrielsarystaff
101.2.3bob1.2.3johnbobstaff
111.2.4tesla1.2.4johnteslastaff
122bush2.top managerbushmanager
132.1george2.1bushgeorgestaff
142.2olof2.2busholofmanager
152.2.1steven2.2.1olofstevenstaff
162.2.2kent2.2.2olofkentstaff
Parent Child (2)
Cell Formulas
RangeFormula
E2=Table1[@item]&IF(FIND(".",Table1[@item]&".")Table1[@item]),"",".")
F2=IF(RIGHT([@item],1)=".","top manager",LOOKUP(2,1/(LEN(E$2:E2)[@item])),G$2:G2))
G2=Table1[@Name]
H2=IF(COUNTIF([item],[@item]&"*")>1,"manager","staff")



Edit: BTW, please investigate the link in my signature block below for providing sample data that we can copy, so we don't have to type it out manually
 
Last edited:
Upvote 0
To convert the values in column A to text you can use
Select A2:A16
Data > Text to columns
Delimited
Next
Next
In step 3 pick Text
Finish

Done!

M.
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

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