看楼主原代码的意图没有楼主表述的清楚,简单地改改,供参考。 Private Sub CommandButton7_Click() Dim i%, j%, irow% Dim v As Range, m% With Sheet2 For Each v In Sheet2.Range("a5:G8") v = Me.Controls("TextBox" & m + 3).Value m = m + 1 Next Sheet2.Cells(2, 8) = TextBox1.Text '单号 Sheet2.Cells(3, 2) = TextBox2.Text Sheet2.Cells(3, 8) = DTPicker1.Value End With
With Sheet4 irow = .Cells(65535, 1).End(xlUp).Row + 1 For i = 0 To 3 If Me.Controls("TextBox" & i * 7 + 3).Text = "" Then Exit For End If .Cells(irow, 1) = Me.DTPicker1.Value .Cells(irow, 2) = Me.TextBox1.Value .Cells(irow, 10) = Me.TextBox2.Value For j = 1 To 7 .Cells(irow, 2 + j) = Me.Controls("TextBox" & i * 7 + 2 + j).Text Next j If Me.OptionButton2 Then .Cells(irow, 6) = -.Cells(irow, 6) .Cells(irow, 7) = -.Cells(irow, 7) .Cells(irow, 9) = -.Cells(irow, 9) End If irow = irow + 1 Next i End With Unload Me End Sub
|