Desired Output should start from A8 row我想开始捕获来自特定行范围的数据,例如A8
并继续下一行。在我的代码中,我在选择范围时遇到错误,任何人都可以指导我解决此错误。
以下是附加代码:
Private Sub cmdadd_Click()
Dim StockNumber As Long, LastRow As Long
Dim wsStockSheet As Worksheet
Set wsStockSheet = ThisWorkbook.Worksheets("Sheet1")
StockNumber = Application.Max(wsStockSheet.Columns(1)) + 1
With wsStockSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Range("A8").Select
.Range("A" & LastRow).Value = StockNumber
.Range("B" & LastRow).Value = Me.cbodd.Text
.Range("C" & LastRow).Value = Me.txtPro.Text
.Range("D" & LastRow).Value = Me.txtEn.Text
End With
End Sub
你自己的代码评论。
Private Sub cmdadd_Click() 'each time you press button cmadd
Dim StockNumber As Long, LastRow As Long
Dim wsStockSheet As Worksheet
Set wsStockSheet = ThisWorkbook.Worksheets("Sheet1")
StockNumber = Application.Max(wsStockSheet.Columns(1)) + 1 'Find the maximun value in column A. Then add one.
With wsStockSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 'Find last row. Then add one (i.e., the row following last with data)
If (LastRow < 7) Then LastRow = 8 'If last row with data is less than 8, then make it be 8
'in columns A, B, C and D of that row, write the corresponding textbox data
.Range("A" & LastRow).Value = StockNumber
.Range("B" & LastRow).Value = Me.cbodd.Text
.Range("C" & LastRow).Value = Me.txtPro.Text
.Range("D" & LastRow).Value = Me.txtEn.Text
End With
End Sub