作者:手机用户2502941585_336 | 来源:互联网 | 2023-05-28 12:36
1> Chrismas007..:
我假设您想要TextBox3
在A列和ComboBox1
B列中.如果您想要不同的列,只需更改字母引用.
Sub OnClick() 'whatever your current sub is called.
Dim LastRow As Long, ws As Worksheet
Set ws = Sheets("Name of Sheet where data is going")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row
ws.Range("A" & LastRow).Value = TextBox3.Text 'Adds the TextBox3 into Col A & Last Blank Row
ws.Range("B" & LastRow).Value = ComboBox1.Text 'Adds the ComboBox1 into Col B & Last Blank Row
End Sub
如果你想要一个方法使用Offset()
:
Sub OnClickwithOffset() 'whatever your current sub is called.
Dim LastRow As Long, ws As Worksheet
Set ws = Sheets("Name of Sheet where data is going")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row
ws.Range("A" & LastRow).Value = TextBox3.Text 'Adds the TextBox3 into Col A & Last Blank Row
ws.Range("A" & LastRow).Offset(0, 1).Value = ComboBox1.Text 'Adds the ComboBox1 into next cell to the right of TextBox3 data.
End Sub