Not sure what you are trying to do, but I think that type of coding would be more appropriate as a virtual basic macro that you call rather than a formula embedded in a cell. If it doesn't work the first time, editing an debugging will be a nightmare.
The industry average is around 40 errors per thousand lines of code (before reviews). At 8000 characters, you probably have 4 errors... In each third... (I figured using 80 characters per line, which is really a long line)
RM