【发布时间】:2018-01-25 23:33:53
【问题描述】:
我有一些我在 VBA 中使用的代码,我通过 VBA 表单将数据输入到 Excel 工作表中,该表单将同时垂直和水平填充 Excel 工作表,但每次我输入一个字母时它都会跳过在表单中提交之前没有完整输入单词的下一列和下一行。请问这个怎么解决。
Private Sub txtLocation_Change()
Dim ws As Worksheet
Set ws = Worksheets("Location")
Dim newRow As Long
newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1
newCol = Application.WorksheetFunction.CountA(ws.Range("B:H")) + 1
ws.Cells(newRow, 1).Value = Me.txtLocation.Value
ws.Cells(1, newRow).Value = Me.txtLocation.Value
End Sub
这是显示的内容
【问题讨论】:
-
每次内容改变时触发该事件,例如添加单个字母。
-
是的。按照@CLR 所说,从
txtLocation框中的Change事件中删除代码,并使用命令按钮更新文本框值(一旦完全输入)。