Parent/Child Macro

  • Thread starter Thread starter turtle
  • Start date Start date
T

turtle

I am looking to get some big time help on writing a macro or formula
to fill out the parent id based on the child id. I have filled out
some of the parent id's to show how it should look. Basically the
parent id follows a general wbs structure where .01.01 would be the
parent of .01.01.01. Any help would be fantastic.
thanks

Child id Parent id
V/0047.FNG.01.01
V/0047.FNG.01.01.01 V/0047.FNG.01.01
V/0047.FNG.01.02 V/0047.FNG.01
V/0047.FNG.01.02.01 V/0047.FNG.01.02
V/0047.FNG.01.03 V/0047.FNG.01
V/0047.FNG.01.03.01 V/0047.FNG.01.03
V/0047.FNG.01.03.02 V/0047.FNG.01.03
V/0047.FNG.01.03.03 V/0047.FNG.01.03
V/0047.FNG.01.03.04 V/0047.FNG.01.03
V/0047.FNG.01.03.05 V/0047.FNG.01.03
V/0047.FNG.01.03.06 V/0047.FNG.01.03
V/0047.FNG.01.04
V/0047.FNG.01.04.01
V/0047.FNG.01.04.02
V/0047.FNG.01.04.03
V/0047.FNG.01.04.04
V/0047.FNG.01.05
 
Is the Parent *ALWAYS* the same as the Child except that the last ".nn" is
missisng?

Function ParentCode(ChildCode As String) As String
If Len(ChildCode) <= 16 Then
ParentCode = vbNullString
Else
ParentCode = Left(ChildCode, Len(ChildCode) - 3)
End If
End Function

or if length of the code doesn't matter, use just

Function ParentCode(ChildCode As String) As String
ParentCode = Left(ChildCode, Len(ChildCode) - 3)
End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top