0

我是 VBA 的新手,并且对此用户窗体的输出有问题。

Private Sub btnSubmit_Click()
Dim RowCount As Long

...

RowCount = Worksheets("Assignments").Range("A3").CurrentRegion.Rows.Count
With Worksheets("Assignments").Range("A3")
    .Offset(RowCount, 0).Value = Me.txtReportAddress.Value
    .Offset(RowCount, 1).Value = Me.cmbCityCounty.Value
    .Offset(RowCount, 2).Value = Me.txtFee.Value
    .Offset(RowCount, 3).Value = Me.txtDate.Value
    .Offset(RowCount, 4).Value = Me.cmbPropertyType.Value
    .Offset(RowCount, 5).Value = Me.txtComments.Value
End With

它给出了正确的输出,但任何后续条目都会覆盖过去的整体。

任何帮助表示赞赏!

4

1 回答 1

0

不熟悉“CurrentRegion”,但看起来您正在计算行数,然后覆盖最后一行;您计算 5 行,然后写入第 5 行,这是包含数据的最后一行,是否像在 RowCount 中加 1 一样简单?

或者,我对这样的事情所做的是:

RowCount = Application.CountA(Worksheets("Assignments").Columns("A"))
    ' Depending on what is in rows 1 and 2 of colomn A you may need to adjust
    ' ie if row 2 is blank then the count will be 1 higher than needed so you 
    ' can adjust accordingly
Dim c as Range
Set c = Worksheets("Assignments").Range("A" & RowCount + 1)
With c
    .value = Me.txtReportAddress.Value
    .Offset(0,1).Value... etc as per your code

希望这能回答你的问题。

于 2013-04-21T23:35:01.123 回答