Excel vba IF THEN ELSE statement

Hi.  I have two Subs:

   one inserts a shape (“Checkmark”) on top of another shape, a square, and

   one erases a shape (“Checkmark”) when it is selected.

When a user double-clicks on a particular square, one of two things must happen:

    a) If the square is empty, a checkmark gets inserted into the square;

    b) If the square already has a checkmark in it, the checkmark gets erased.

My problem is:  I’m having trouble writing an If Then Else statement that works!

       “If there’s no checkmark in the square, then insert one;

       Else

       If the square contains a checkmark, erase it.”

Both of the existing subs work properly.  And, the  _BeforeDoubleClick_ action also works fine.  But I can’t make the If Then Else statement work properly.  Help, please!  Thank you.

 

The existing subs:

     Sub EraseCheckmark()

         SendKeys “{DEL}”

      End Sub

 

Sub PlaceCheckmark()

    ActiveSheet.Shapes.Range(Array(“Checkmark”)).Select

    Selection.Copy

    ActiveCell.Offset(0, 0).Range(“A1”).Select

    ActiveSheet.Paste

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementTop 0.3750393701

    Selection.ShapeRange.IncrementLeft 0.3750393701

    Cancel = True

    SendKeys “{ESC}”

    newHour = Hour(Now())

    newMinute = Minute(Now())

    newSecond = Second(Now()) + 2

    waitTime = TimeSerial(newHour, newMinute, newSecond)

    Application.Wait waitTime

End Sub

By: Robin Miller

Leave a Reply

Your email address will not be published. Required fields are marked *