2013-04-21 97 views
0

我是VBA的新品牌,並且遇到此UserForm的輸出問題。VBA Excel - 在編寫之前檢查單元格內容

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 

它給正確的輸出,但任何後續條目將覆蓋過去entires。

任何幫助表示讚賞!

回答

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 

希望這回答了你的問題。

相關問題