Hello everyone,
I am still quite inexperienced in Excel VBA and have encountered a problem. The background:
I would like to fill various shapes with small rectangles (‘modules’). The modules should always be the same size and their size is predefined. A minimum distance between the modules and to the edge of the respective shape is also specified. Taking these conditions into account, as many modules as possible should be generated symmetrically in the shape. The size of the mould should be variable so that the maximum number of modules can always be generated.
This is not a problem with a rectangular shape (see ‘Sheet1’ and sub ‘GenerateModulesSquare’.
Next, I tried my hand at a trapezoid. I first determined the 4 corner points of the trapezoid to determine the edges. I then used a loop to query whether there was room for another module + two safety distances to the edge (see subs ‘TrapezoidTooManyModules’ and ‘TrapezoidNotEnoughModules’).
Especially with ‘TrapezoidNotEnoughModules’ I don't understand why gaps are left where there would actually be enough space for further modules.
‘TrapezoidTooManyModules’ looks better at first glance, but exceeds the edges of the trapezoid.
Depending on whether you enlarge or reduce the size of the trapezoid, the malfunction becomes clearer. Neither of the two approaches works.
I suspect that I am not calculating the left and right edges accurately and therefore the If queries are correct, but have the wrong basis.
I would be very grateful for any advice!
Bookmarks