# Excel - Checkbox Names



## KenPopcorn (Aug 18, 2009)

I have a spreadsheet that uses macros to format input screens, which include varying numbers of checkboxes. I want to write additional macros to run based on the value of the checkbox. 

The problem I find is that everytime I refresh the sheet, the new checkbox has the number embedded in its name incremented. For instance when I look at the sheet I see the checkboxes named Checkbox1171 through Checkbox1180. If I refresh again, they become Checkbox1181 through Checkbox1189.

If I could either define the name when I create the checkbox, or if I could reset this counter, I'd be OK. I can't seem to find the way to do either.

Any thoughts? Thanks.


----------



## drewkeller (Aug 1, 2009)

So sometimes you want it to create new checkboxes and other times you want it to use existing checkboxes? Can you better define when you want to do which?

The more I try to figure out what you're doing, the more ambiguous it sounds. Since you mention refreshing, you must be working with some kind of external data. The external data must represent "input screens".... are you formatting data entered by the user or formatting the data into some kind of generated code to create input screens? It is not clear how the checkboxes relate to the data.

Anyway, maybe that doesn't matter.

Resetting a counter in Visual Basic is easy. If your counter is called iCheckBoxCounter, you just do this:
iCheckBoxCounter = 0
That's probably too simple to be helpful. 

If you're using form controls, did you try naming them like this (you can also do checkboxes with ActiveX controls)...
ActiveSheet.CheckBoxes(1).Name = "NewName"

t's hard to say exactly what to do without seeing some of your existing code.


----------



## KenPopcorn (Aug 18, 2009)

Sorry to be vague, I'm a bit of a newbie at this.

My sheet is used to input data to set up accounts. There are radio buttons to allow you to select 1 of 3 types of account. Based on the type selected, I set up the input page with 5,6 or 7 account number and amount fields. Next to some of the fields I place a checkbox indicating whether that field will be input into this particular account.

Currently I use this process with 3 different spreadsheets, and it works fine. My goal is to combine into a single spreadsheet, with the option to choose the type of account. This is the reason I am refreshing the input screen with varying numbers of checkboxes.

If I were able to reset the checkbox counter, or specify a name so I can run an appropriate macro, I'd be all set. In short, if I have 5 checkboxes on the screen, I'd like them to always be named Checkbox1 - Checkbox5 instead of always incrementing the number.

Does that help?


----------



## drewkeller (Aug 1, 2009)

So if I understand correctly, no checkboxes are being created when the form is filled out.
By "refresh" you mean reset existing checkboxes and form fields to initial values (unchecked and blank, respectively).

I don't see any reason for needing new checkboxes and I don't know why they would be getting their numbers increased (of course, if you're copying and pasting them from a different spreadsheet, they will be assigned different numbers when they are pasted so they don't conflict with your existing ones). If you post some code or your Excel file, I could probably tell you.

I also don't know why the checkboxes would be presenting a problem and your other controls are fine.

Are you using form controls or ActiveX controls? If you right click on your checkbox, does it have a Checkbox Object item on the menu? If yes, then it's ActiveX.

To clear them, you could do something like (form controls)....

```
Sub ResetAllCheckboxes
    With ActiveSheet
        For Each chk In .CheckBoxes
            chk.Value = False
        Next
    End With
End Sub
```
If you create a command button that executes the above, you can clear the checkboxes by clicking on the button.


----------

