答案 0 :(得分:0)
正如我在评论中所述,您应该使用Option Explicit
,否则不会在每个Sub中本地定义staff_name。
我假设您发布的代码在用户表单的模块中。然后,以下更改可以修复您的代码
Option Explicit
Dim staff_name as string
Private Sub txtstaffname_Change()
staff_name = txtstaffname.Value
End Sub
_________________________________________________________________________
Private Sub Done_Click()
dim r as long
'Updat Maintenance Sheet'
Application.EnableEvents = False
r = Application.CountA(Range("A:A")) + 1
With Worksheets("For Maintenance Propose")
.Cells(1, r).Value = staff_name
End With
Application.EnableEvents = True
End Sub
PS,我也猜想您真的很想填充该列下面的单元格,所以应该是
.Cells(r,1).Value = staff_name