Hi everyone, I am facing a problem in Excel. First, I need to use VBA because it is impossible to add a row in excel without using VBA (of what I know...).
The problem I am facing is that I have a data structure with thousands of lines in a tree type within the same column:
BASIC COLUMN
C1
C1R1
C1R1R1
C1R1R1R1
C1R1R1R2
C1R2
C1R2R1
C1R2R1R1
C2
C2R1
C2R1R1
C2R1R1R1
C2R2
C3
C4
What I would like is that creating a tree network graphic with x and y coordinates by creating key pairs of nodes in type "from-to". (e.g., C1-C1R1; C1R1-C1R1R1; C1R1R1-C1R1R1R1; C1R1R1-C1R1R1R2; and so on...). Each line will contain other information x,y coordinates, attributes, names etc. The thing is that I need to add a new line in order to take into account the "from" node under certain conditions that have to be defined. I have created the basic algorithm in excel in order to understand the logic in doing it with VBA. Here is the data structure I would like to look like afterwards. In bold, you have the new line added (the "from" node) copied.
WANTED RESULT:
C1
C1R1
C1R1
C1R1R1
C1R1R1
C1R1R1R1
C1R1R1
C1R1R1R2
C1
C1R2
C1R2
C1R2R1
C1R2R1
C1R2R1R1
C2
C2R1
C2R1
C2R1R1
C2R1R1
C2R1R1R1
C2
C2R2
C3
C3
C4
C4
Here is the algorithm developed in excel but that can't be used because we can't add rows in excel. But it gives le logic:
Algorithm:
=IF(B17="";
"";
IF(AND(LEN(B17) > LEN(B16);LEN(B17) < LEN(B18));
“add new line and copy B17”;
IF(AND(LEN(B17) > LEN(B16);LEN(B17) > LEN(B18));
"";
IF(AND(LEN(B17) < LEN(B16);LEN(B17) = LEN(B18));
B17;
IF(AND(LEN(B17) < LEN(B16);LEN(B17) < LEN(B18));
B17;
IF(LEN(B17) = LEN(B18);
B16;
IF(AND(LEN(B17)=2;LEN(B18)=2);
B17;
IF(AND(LEN(B17)=2;LEN(B18)="");
“add new line and copy B17”;
IF(LEFT(B17;4) <> LEFT(B18;4);
"Come back to the parent node";
""
)))))))))
Any thoughts? It would save me so much time. Thanks in advance.
Cheers.
The problem I am facing is that I have a data structure with thousands of lines in a tree type within the same column:
BASIC COLUMN
C1
C1R1
C1R1R1
C1R1R1R1
C1R1R1R2
C1R2
C1R2R1
C1R2R1R1
C2
C2R1
C2R1R1
C2R1R1R1
C2R2
C3
C4
What I would like is that creating a tree network graphic with x and y coordinates by creating key pairs of nodes in type "from-to". (e.g., C1-C1R1; C1R1-C1R1R1; C1R1R1-C1R1R1R1; C1R1R1-C1R1R1R2; and so on...). Each line will contain other information x,y coordinates, attributes, names etc. The thing is that I need to add a new line in order to take into account the "from" node under certain conditions that have to be defined. I have created the basic algorithm in excel in order to understand the logic in doing it with VBA. Here is the data structure I would like to look like afterwards. In bold, you have the new line added (the "from" node) copied.
WANTED RESULT:
C1
C1R1
C1R1
C1R1R1
C1R1R1
C1R1R1R1
C1R1R1
C1R1R1R2
C1
C1R2
C1R2
C1R2R1
C1R2R1
C1R2R1R1
C2
C2R1
C2R1
C2R1R1
C2R1R1
C2R1R1R1
C2
C2R2
C3
C3
C4
C4
Here is the algorithm developed in excel but that can't be used because we can't add rows in excel. But it gives le logic:
Algorithm:
=IF(B17="";
"";
IF(AND(LEN(B17) > LEN(B16);LEN(B17) < LEN(B18));
“add new line and copy B17”;
IF(AND(LEN(B17) > LEN(B16);LEN(B17) > LEN(B18));
"";
IF(AND(LEN(B17) < LEN(B16);LEN(B17) = LEN(B18));
B17;
IF(AND(LEN(B17) < LEN(B16);LEN(B17) < LEN(B18));
B17;
IF(LEN(B17) = LEN(B18);
B16;
IF(AND(LEN(B17)=2;LEN(B18)=2);
B17;
IF(AND(LEN(B17)=2;LEN(B18)="");
“add new line and copy B17”;
IF(LEFT(B17;4) <> LEFT(B18;4);
"Come back to the parent node";
""
)))))))))
Any thoughts? It would save me so much time. Thanks in advance.
Cheers.