我很抱歉,如果在之前的帖子中已经回答了这个问题,我会搜索一段时间,但我真的不确定我要问的问题是什么。
我对VBA很新,这是我第一次真正涉足它。
我遇到的问题是VBA将表单内容粘贴到电子表格中,电子表格在第一列中有一个vlookup参考列(该表需要对表单进行excel查找,因此需要此引用)
我目前正在使用一个按钮: -
Private Sub submit_Click()
Dim RowCount As Long
RowCount = Worksheets("Raw Data").Range("B1").CurrentRegion.Rows.Count
Private Sub submit_Click()
With Worksheets("Raw Data").Range("B1")
.Offset(RowCount, 0).Value = Format(Now, "dd/mm/yyyy")
.Offset(RowCount, 1).Value = Me.operator.Value
.Offset(RowCount, 2).Value = Me.custexp.Value
.Offset(RowCount, 3).Value = Me.fcr.Value
.Offset(RowCount, 4).Value = Me.opfcr.Value
.Offset(RowCount, 5).Value = Me.compliant.Value
.Offset(RowCount, 6).Value = Me.summary.Value
.Offset(RowCount, 7).Value = Me.evaluation.Value
.Offset(RowCount, 8).Value = Me.compliance.Value
.Offset(RowCount, 9).Value = Me.callid.Value
.Offset(RowCount, 10).Value = Me.calltime.Value
.Offset(RowCount, 11).Value = Me.leader.Value
.Offset(RowCount, 12).Value = Me.custnum.Value
End With
Dim ctl As Control
End Sub
但是这会找到第一个完全空白的单元格并避免使用公式中的任何内容。
无论如何都要绕过这个?
答案 0 :(得分:0)
也许是这样的:
Private Sub submit_Click()
Dim c As Range
'find first empty cell in ColB (looking from the bottom of the sheet)
Set c = Worksheets("Raw Data").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
With c.EntireRow
.Cells(2).Value = Format(Now, "dd/mm/yyyy")
.Cells(3).Value = Me.Operator.Value
.Cells(4).Value = Me.custexp.Value
.Cells(5).Value = Me.fcr.Value
.Cells(6).Value = Me.opfcr.Value
.Cells(7).Value = Me.compliant.Value
.Cells(8).Value = Me.Summary.Value
.Cells(9).Value = Me.evaluation.Value
.Cells(10).Value = Me.compliance.Value
.Cells(11).Value = Me.callid.Value
.Cells(12).Value = Me.calltime.Value
.Cells(13).Value = Me.leader.Value
.Cells(14).Value = Me.custnum.Value
End With
End Sub