placing checkbox value into sheet via userform

keithkemble

Board Regular
Joined
Feb 15, 2002
Messages
160
I am trying to put the value of the checkbox (1 if true, 0 if false) into a cell in the sheet.

The first sub does yield the correct values while running, but when I get to the writedata sub it has lost its value despite being Publi.

Can any one advise how to hold on to the value. All subs are in the same Userform module.
The name of the checkbox is checkbox1

Public Sub checkBox1_Click()
Dim Chk1 As Variant
If CheckBox1.Value = True Then
Chk1 = 1
Else: Chk1 = 0
End If

End Sub'
Sub WriteData(dbRow As Integer)
Dim i As Integer, fieldValue As Variant

' Enter data in fields
'
For i = 1 To totalFields
fieldValue = textBoxes(textboxNames(i - 1)).Text
Cells(dbRow, i).Offset(0, 4).Value = fieldValue
Next 'i

Cells(dbRow, i).Offset(0, 0).Value = Chk1
Cells(dbRow, i).Offset(0, 1).Value = Chk2
'
' Select first cell in record
'
' Cells(dbRow, 1).Select
End Sub

Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I gave it a go but it does not work.

I put a watch on the variable. During the click routine the variable holds 1 but when it get to the write routine it is empty.
 
Upvote 0
Why don't you set the value in the WriteData routine?

if sheets(1).CheckBox1.value then Cells(dbRow, i).Offset(0, 0).Value = 1
 
Upvote 0
The checkbox is on a userform (not a sheet) and therefore I have to carry the value in a variable.

The rest of the routine (the other text is placed correctly in the list)
MY problem is I am Losing the stored value.
 
Upvote 0
On 2002-09-16 08:57, keithkemble wrote:
The checkbox is on a userform (not a sheet) and therefore I have to carry the value in a variable.

The rest of the routine (the other text is placed correctly in the list)
MY problem is I am Losing the stored value.

Try this
"Public Chk1 As Variant" in Module-> general->declaration
 
Upvote 0

Forum statistics

Threads
1,224,265
Messages
6,177,521
Members
452,782
Latest member
ZCapitao

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