PDA

View Full Version : Need to change text of .CheckBox through a counter



Quester
10-26-2008, 07:15 AM
Hi

I'm kind of new to this, so I hope you can help me anwear this "simple" question.

A part of my code is supose to check my CheckBox'es, but have a problem with the following part of the code.
...
Do While Worksheets("Prisliste").CheckBox1 = True
...

The code above works perfectly, but I need to have a counter after the class, witch the system refuses me to do. I would like to have it like this:

...
Do While Worksheets("Prisliste").CheckBox & counter = True
...

Is there any way to have a changeable counter as a part of that expression?

Thanx for all help!

Regards

Quester

Bob Phillips
10-26-2008, 07:51 AM
Do While Worksheets("Prisliste").CheckBox And counter = True

Quester
10-26-2008, 11:16 AM
Thanx, but I get this wellknowed error: "Object doesn't support this property or method" :dunno

Bob Phillips
10-26-2008, 11:46 AM
We'll need a ton more detail, or even a sample workbook.

Quester
10-26-2008, 02:38 PM
ok, here we have a small (Working) part of the code. Hope anyone have a solution.


Private Sub CommandButton1_Click()

' I have removed deklaration.. too much of it :)

' Give values, and tells witch line you can find the info for first line
nr = 1
rad1 = "B" & 1
rad2 = "F" & 1
ytRad1 = "B" & 8
ytRad2 = "F" & 8
ytpRad1 = "C" & 8
ytpRad2 = "G" & 8
stRad1 = "D" & 8
stRad2 = "H" & 8

' First loop: Look for checkbokser with is enabled, and tells what line it's
' on.

' This is my problem.. I need the checkbox to be counted like in the first
' post (something like .CheckBox And nr = True).

Do While Worksheets("Prisliste").CheckBox1 = True
LRow = CheckBox1.TopLeftCell.Row

rowTlf = "B" & LRow
rowYt = "D" & LRow
rowYtp = "E" & LRow
rowSt = "F" & LRow

' If the checkbox is enabled, then find an open space in the "etiketter"
' sheet. We find first the Row.

Do While result = Worksheets("Etiketter").Range(rad1).Value Or Worksheets("Etiketter").Range(rad2).Value = ""

' and then wich of the two spaces witch is open
If Worksheets("Etiketter").Range(rad1) = "" Then

' Gets information from the right row in the "Prisliste" sheet.
tlf = Worksheets("Prisliste").Range(rowTlf).Value
tlfyoungtalk = Worksheets("Prisliste").Range(rowYt).Value
tlfyoungtalkplus = Worksheets("Prisliste").Range(rowYtp).Value
tlfsupertalk = Worksheets("Prisliste").Range(rowSt).Value

' Past in the information grabbed (Row1)
Worksheets("Etiketter").Range(rad1).Value = tlf
Worksheets("Etiketter").Range(ytRad1).Value = tlfyoungtalk
Worksheets("Etiketter").Range(ytpRad1).Value = tlfyoungtalkplus
Worksheets("Etiketter").Range(stRad1).Value = tlfsupertalk

Else

' Gets information from the right row in the "Prisliste" sheet.
tlf = Worksheets("Prisliste").Range(rowTlf).Value
tlfyoungtalk = Worksheets("Prisliste").Range(rowYt).Value
tlfyoungtalkplus = Worksheets("Prisliste").Range(rowYtp).Value
tlfsupertalk = Worksheets("Prisliste").Range(rowSt).Value

' Past in the information grabbed (Row2)
Worksheets("Etiketter").Range(rad2).Value = tlf
Worksheets("Etiketter").Range(ytRad2).Value = tlfyoungtalk
Worksheets("Etiketter").Range(ytpRad2).Value = tlfyoungtalkplus
Worksheets("Etiketter").Range(stRad2).Value = tlfsupertalk

counter = counter + 32

' Tells witch place it will have on the next row.
rad1 = "B" & counter
rad2 = "F" & counter
ytRad1 = "B" & counter + 7
ytRad2 = "F" & counter + 7
ytpRad1 = "C" & counter + 7
ytpRad2 = "G" & counter + 7
stRad1 = "D" & counter + 7
stRad2 = "H" & counter + 7

End If

' nr is supose to be changeing the CheckBox counter

Loop

nr = nr + 1

Loop

End Sub

peterzum
01-17-2009, 02:38 AM
I had to do a similar thing. This is how I looked at the value of my checkbox list:

if (Worksheets("Sheet1").OLEObjects("CheckBox" & nr).Object.Value) = True then ' do something
my Checkboxes were created as OLEObjects though with the following code:
Worksheets(sheet_name).OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=Range("C" & nr).Left, Top:=Range("C" & nr).Top, _
Width:=32, Height:=10).Select
This uses the generic name for the check box automatically created for the checkbox. i.e. "CheckBox1", "CheckBox2" etc.