Excel VBA将单元格数据保存到单独的工作表中
我如何将工作表1中的单元格数据保存到工作表2中。
基本上我有这样的一张表:
| Job number | Job notes edit button | 345345 | just some text edit button | 345468 | more text edit button | 678934 | job info
在我的Excel工作表中,每一行上都有一个命令button,当按下后,用户可以用文本框打开一个用户窗体,当命令button被按下时,它会有一个命令button,它将search作业编号并将文本框数据保存到行正在编辑的正确的工作号码。
代码保存
Private Sub savejobnotes_Click() Dim YourVariable As Variant Dim rowCount As Integer Dim rownum As String Set YourVariable = jobRef With ActiveSheet.Range("D:D") Set uRng = .Find(YourVariable, , xlValues, xlWhole, , MatchCase:=False, searchformat:=False) If Not uRng Is Nothing Then uRng.Activate rowCount = ActiveCell.Row 'this will find the row number rowCount ' MsgBox rowCount rownum = "K" & rowCount MsgBox "Saved to " & rownum 'save textbox value to a cell ActiveSheet.Range(rownum).Value = jobnotes.Value End If End With End Sub
打开用户表单时将代码加载到文本框中的代码。
Sub loadjobnotes() Dim YourVariable As Variant Dim rowCount As Integer Dim rownum As String Set YourVariable = jobRef With ActiveSheet.Range("D:D") Set uRng = .Find(YourVariable, , xlValues, xlWhole, , MatchCase:=False, searchformat:=False) If Not uRng Is Nothing Then uRng.Activate rowCount = ActiveCell.Row 'this will find the row number rowCount ' MsgBox rowCount rownum = "K" & rowCount ' MsgBox rownum jobnotes.Value = ActiveSheet.Range(rownum) End If End With End Sub
我如何每次将作业编号和工作logging保存到单独的工作表中。 因为我需要保留一份与工作号码相关的工作logging副本,因为我的Excel工作表定期从.csv文件更新,从表格中删除所有已完成的工作。
谢谢你的帮助
您应该先创build一个名为“ Jobs”的新工作表,然后使用如下所示的构造:
Sheets("Jobs").Cells("coordinates here").Value = "your values"
也许你会需要创build一个计数器,但这是另一个话题。