保存表单时填充三列
我有以下表格,应在数据提交表格之前完成:
我试图编写它,所以完成后的forms,当点击保存button,它会findA列中的第一个空单元格,并从上面复制公式,我已经设法做到这一点,但现在我想选项卡插入B列,并像以前一样从上面复制公式。
THEN“标签插入C列,并按照我创build的窗体顺序input数据到相邻的单元格中。
这是我的代码,但我真的在这里黑暗!
Private Sub CommandButton2_Click() Dim irow As Long Dim ws As Worksheet Set ws = Worksheets("Master Data") NextFree = Range("A10:A" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row Range("A" & NextFree).Select ' Copy formula from cell above Dim oCell As Range For Each oCell In Selection If (oCell.Value = "") Then oCell.Offset(-1, 0).Copy Destination:=oCell End If Next oCell End Sub ' Move to adjacent cell Sub MoveOver() ActiveCell.Offset(0, 1).Select End Sub 'Insert data into cells Sub LastRow() .Offset(1, 0) = ComboBox1.Text .Offset(1, 1) = TextBox1.Value .Offset(1, 2) = TextBox2.Value .Offset(1, 3) = TextBox3.Value .Offset(1, 4) = TextBox4.Value .Offset(1, 5) = TextBox5.Value .Offset(1, 6) = TextBox6.Value End Sub
难道这是你要找的东西吗?
Dim lstRw As Long lstRw = Cells(Rows.Count, "A").End(xlUp).Row Range("A" & lstRw & ":B" & lstRw).Copy Range("A" & lstRw + 1)
你可以保持它在同一个子,如
Dim lstRw As Long Dim Rng As Range lstRw = Cells(Rows.Count, "A").End(xlUp).Row Set Rng = Range("A" & lstRw + 1) Range("A" & lstRw & ":B" & lstRw).Copy Range("A" & lstRw + 1) With Rng .Offset(, 2) = ComboBox1.Text .Offset(, 3) = TextBox1.Value .Offset(, 4) = TextBox2.Value .Offset(, 5) = TextBox3.Value .Offset(, 6) = TextBox4.Value .Offset(, 7) = TextBox5.Value .Offset(, 8) = TextBox6.Value End With