Ojects and Conditional Statements - Help, please

XLXRider

Board Regular
Joined
Jul 31, 2004
Messages
180
Good morning...

I have a really crumby form that I've been tasked with updating. I need to have a few boxes that Excel-challenged users can readily check and/or uncheck. I don't want to use checkbox... so what I've done is made an object and placed an "X" in it, or not. The code to do one or the other is a snap, but what I want to do is combine the code into a command button, and I will make one command button for each check/uncheck instance since there are only 5 or 6 in the entire form. Here's my problem:
I can't seem to get the conditional statement to work, and don't know if it's because conditional statements won't work with objects or because I'm doing it incorrectly!

Here's the code I've been working with:

Sub toggleX()

ActiveSheet.Shapes("XBoxEmpty").Select
With Selection.Characters.Text
If .Shapes("XBoxEmpty").Characters.Text = "" Then
.Shapes("XBoxEmpty").Characters.Text = "X"
Else
.Shapes("XBoxEmpty").Characters.Text = ""
End If
End With

End Sub

The object name I'm working with in my experiments is XBoxEmpty, and I want the user to look at the box and be able to change the state from "X" to "" with the same button. That is, if the user puts in an X and realizes it should be empty, the same button does it. And vice-versa.

Thanks in advance,
XLXRider
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Will work with all of your shapes that have this macro assigned to it. Download example if necc.

<a href="http://home.fuse.net/tstom/323627.060708.0940.zip"><img src="http://home.fuse.net/tstom/zip.gif"width="16"height="16"border="0"></a> <a href="http://home.fuse.net/tstom/323627.060708.0940.zip">323627.060708.0940.zip</a>

Code:
Sub toggleX()
    With ActiveSheet.Shapes(Application.Caller)
        If .TextFrame.Characters.Text = "" Then
            .TextFrame.Characters.Text = "X"
        Else
            .TextFrame.Characters.Text = ""
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,007
Messages
6,122,670
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top