Hi everyone, thank you for your time.
I'm building an Excel form that transfers info into another sheet in the same workbook. However, some of the cells contains checkboxes, and I want to write the captions of these checkboxes into the corresponding cells before transfering all the data into the other sheet.
Below is my code. The indented part is where I try to write the checkboxes captions. All of typed data is recorded successfully but checkboxes aren't, and I don't know why.
Could you please show me where I got it wrong?
I'm building an Excel form that transfers info into another sheet in the same workbook. However, some of the cells contains checkboxes, and I want to write the captions of these checkboxes into the corresponding cells before transfering all the data into the other sheet.
Below is my code. The indented part is where I try to write the checkboxes captions. All of typed data is recorded successfully but checkboxes aren't, and I don't know why.
Could you please show me where I got it wrong?
VBA Code:
Option Explicit
Sub save()
Dim form As Worksheet
Dim database As Worksheet
Dim database_row As Long
Dim database_column As Integer
Dim form_row As Integer
Set form = ThisWorkbook.Sheets("Form")
Set database = ThisWorkbook.Sheets("Database")
form_row = 5
'add value of checkboxes to corresponding cells
Dim cb As CheckBox
For Each cb In form.CheckBoxes
If cb.Value = True Then
cb.toplelfcell = cb.TopLeftCell & cb.Caption & vbCrLf
End If
Next cb
'define database row number
database_row = database.Range("A" & Application.Rows.Count).End(xlUp).Row + 1
'transfer data from form to database
For database_column = 1 To 49
'look for rows in the from with data
While form.Cells(form_row, 3) = ""
form_row = form_row + 1
Wend
'record data
database.Cells(database_row, database_column) = form.Cells(form_row, 5)
'reset form field to empty
form.Cells(form_row, 5) = ""
form_row = form_row + 1
Next database_column
End Sub
Last edited: