base game has 8 fluids: water, oil, heavy oil, petroleum, light oil, lubricant, steam, sulfuric acid.
add mods to that and it can go well over 240. not sure if lua has a square root function, but i'd use a variation on that... like take the square root of how many fluids there are, then add 1 and set the columns to that value. or you can do something like :
if count of fluids < nNumber then set number of columns to 7. else if number of fluids is greater than nNumber, take the squareRoot and add one to it and have that be set as the number of columns.
edit: technically, you can add 1 or subtract 1 and floor the result to get a less-square GUI. if however, you're dead set on there being a specific number of columns, check out how a few other mods have set up pages or scrolling in their guis.