我在excel VBA中创建了一个userform,由于某种原因,我的值没有复制到电子表格中。以下是用于写入数据的代码行:
Dim RowCount as long
RowCount = Worksheets("Request Log").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Request Log").Range("A1")
.Offset(RowCount, 0).Value = DateValue(Me.txtDate.Value)
.Offset(RowCount, 1).Value = Me.BuyerComboBox.Value
.Offset(RowCount, 2).Value = Me.txtItem.Value
.Offset(RowCount, 3).Value = Me.txtDes.Value
.Offset(RowCount, 4).Value = Me.txtCost.Value
.Offset(RowCount, 5).Value = Me.txtQty.Value
.Offset(RowCount, 6).Value = DateValue(Me.txtNeed.Value)
.Offset(RowCount, 7).Value = Me.ReasonListBox.Value
.Offset(RowCount, 8).Value = Me.txtDetails.Value
End With
请帮忙!!谢谢!
答案 0 :(得分:0)
更改为:
'RowCount = Worksheets("Request Log").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Request Log")
RowCount = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
With Worksheets("Request Log").Range("A1")
.Offset(RowCount, 0).Value = DateValue(Me.txtDate.Value)
.Offset(RowCount, 1).Value = Me.BuyerComboBox.Value
.Offset(RowCount, 2).Value = Me.txtItem.Value
.Offset(RowCount, 3).Value = Me.txtDes.Value
.Offset(RowCount, 4).Value = Me.txtCost.Value
.Offset(RowCount, 5).Value = Me.txtQty.Value
.Offset(RowCount, 6).Value = DateValue(Me.txtNeed.Value)
.Offset(RowCount, 7).Value = Me.ReasonListBox.Value
.Offset(RowCount, 8).Value = Me.txtDetails.Value
End With