我仍然只是在学习VBA,但是我遇到了以下问题,其中userform输入的数据会覆盖现有的行。
能够帮忙吗?
' Write data to worksheet
rowcount = Worksheets("Register").Range("A4").CurrentRegion.Rows.Count
With Worksheets("Register").Range("A4")
.Offset(rowcount, 0).Value = Me.txtID.Value
.Offset(rowcount, 1).Value = Me.txtRecDate
.Offset(rowcount, 2).Value = Me.txtPerson.Value
.Offset(rowcount, 3).Value = Me.txtEntity.Value
.Offset(rowcount, 4).Value = Me.cboCorresType.Value
.Offset(rowcount, 5).Value = Me.cboInTray.Value
.Offset(rowcount, 6).Value = "FALSE"
.Offset(rowcount, 50).Value = Format(Now, "dd/mm/yyyy hh:mm:ss")
.Offset(rowcount, 51).Value = Environ("Username")
End With
答案 0 :(得分:0)
经过对互联网的更多研究后......
' Write data to worksheet
Set ws = Sheets("Register")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range("A" & LastRow).Value = Me.txtID.Value
ws.Range("B" & LastRow).Value = Me.txtRecDate
ws.Range("C" & LastRow).Value = Me.txtPerson.Value
ws.Range("D" & LastRow).Value = Me.txtEntity.Value
ws.Range("E" & LastRow).Value = Me.cboCorresType.Value
ws.Range("F" & LastRow).Value = Me.cboInTray.Value
ws.Range("G" & LastRow).Value = "FALSE"
ws.Range("AY" & LastRow).Value = Format(Now, "DD/MM/YYYY hh:mm:ss")
ws.Range("AZ" & LastRow).Value = Environ("Username")