如何在单元格中显示我的文本框值?

时间:2016-07-10 07:41:30

标签: vba excel-vba excel

我的用户表单包含很少的文本框,表明他们的值需要在表格的特定单元格中显示。如何在单元格中打印这些值?

'add a new employee to the bottom of the list

'last_row = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row

Cells(last_row, 1) = Box_FirstName.Value
Columns("A:A").EntireColumn.AutoFit

Cells(last_row, 2) = Box_LastName.Value.Value
Columns("B:B").EntireColumn.AutoFit

Cells(last_row, 3) = Box_Adress.Value.Value
Columns("C:C").EntireColumn.AutoFit

Cells(last_row, 4) = Box_ID.Value.Value
Columns("D:D").EntireColumn.AutoFit

1 个答案:

答案 0 :(得分:2)

正如您在代码中所示:

Cells(1, 1) = TextBox1.Value

只需确保用于对单元格添加的变量都不设置为0.

修改 如果您使用Box_FirstName作为String变量并在某些时间更改UserFrom,那么:

Dim Form_Name as Object

Set Form_Name = UserForm1   'UserFrom name
Cells(1, 1) = Form_Name.Controls(Box_FistName).Value