Tom Young
Tom Young

Reputation: 23

Using dynamic "<" or ">" from cell result within an If statement

I am using a cell formula to determine whether a "<" or ">" symbol is required to use within a VBA IF statement.

This is part of a very large algorithm I am creating to draw geometric patterns depending on there line equations on each side.

The "<" or ">" part determines if the shape being inserted is within the drawing area, which can be of any shape and size.

The part I am stuck on:

GreaterORLess = Sheets("shape").Range("L4").value '(will either be a "<" or ">" result in this cell) LeftPos = LeftD + ((L + G) * CountL) 'Top Left position of rectangle being inserted
LineEq = (Sty - B) / m ' angle of boundary line to determine if LeftPos is < or > than

If LeftPos ***[GreaterORLess]*** LineEq Then

    ActiveSheet.Shapes.AddShape(msoShapeRectangle, LeftD + ((l + g) * CountL), topd + (CountW * (W + g)), l, W).Select

End If

I suppose you could look at this like the VBA If statement needs to concatenate the "<" or ">" within the If statement and then evaluate?

Upvotes: 2

Views: 70

Answers (1)

Tim Williams
Tim Williams

Reputation: 166685

GreaterORLess = Sheets("shape").Range("L4").value '(will either be a "<" or ">" result in this cell) 

LeftPos = LeftD + ((L + G) * CountL) 'Top Left position of rectangle being inserted

LineEq = (Sty - B) / m ' angle of boundary line to determine if LeftPos is < or > than

If (GreaterORLess = ">" And LeftPos > LineEq) Or  
   (GreaterORLess = "<" And LeftPos < LineEq) Then

    ActiveSheet.Shapes.AddShape(msoShapeRectangle, _
                      LeftD + ((l + g) * CountL), _
                      topd + (CountW * (W + g)), l, W).Select

End If

Upvotes: 4

Related Questions