从excel userform查找下一个空行以自动输入数据

时间:2013-05-14 14:49:58

标签: excel excel-vba vba

Private Sub CommandButton1_Click()

NextRow = 2

Sheets("data").Cells(NextRow, 2) = Now

Sheets("data").Cells(NextRow, 3) = Sheets("sheet1").Cells(NextRow, 2)

Sheets("data").Cells(NextRow, 4) = ThisWorkbook.Sheets("Sheet1").Range("b3")

Sheets("data").Cells(NextRow, 5) = ThisWorkbook.Sheets("Sheet1").Range("b4")

Sheets("data").Cells(NextRow, 6) = ThisWorkbook.Sheets("Sheet1").Range("b5")

Sheets("data").Cells(NextRow, 7) = ThisWorkbook.Sheets("Sheet1").Range("b6")

Sheets("data").Cells(NextRow, 8) = ThisWorkbook.Sheets("Sheet1").Range("b7")

Sheets("data").Cells(NextRow, 9) = ThisWorkbook.Sheets("Sheet1").Range("b8")

Sheets("data").Cells(NextRow, 10) = ThisWorkbook.Sheets("Sheet1").Range("b10")

Sheets("data").Cells(NextRow, 11) = ThisWorkbook.Sheets("Sheet1").Range("b11")

Sheets("data").Cells(NextRow, 12) = ThisWorkbook.Sheets("Sheet1").Range("b12")
End Sub

这是我的代码。每当我继续给予价值时,它就会覆盖。怎么改呢?如何进入单独的行?

1 个答案:

答案 0 :(得分:1)

你可以弹出一个小循环来发现下一个空行,例如(未经测试!):

NextRow=2
do until Sheets("data").Cells(NextRow,2) = ""
    NextRow = NextRow + 1
Loop