Glad you got it sorted.
But its only hard because of the lack of detail in the question.
What we need are details, examples, expected outcome. Sample files. etc etc.
If all of this information was included in the first place I'm pretty sure you'd have had a solution fairly quickly.
We are not mindreaders.