[英]Excel VBA save cell data to separate sheet
如何將單元格數據從工作表1保存到工作表2。
基本上我有這樣的一張紙:
| Job number | Job notes
edit button | 345345 | just some text
edit button | 345468 | more text
edit button | 678934 | job info
在我的excel表格上,每行上都有一個命令按鈕,當按下該按鈕時,會打開一個帶有文本框的用戶表單,當按下命令按鈕時,它將具有一個命令按鈕,它會搜索作業編號並將文本框數據保存到該行中我正在編輯的正確工作編號。
保存代碼
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
每次如何將工作編號和工作說明保存到單獨的工作表中。 由於我的Excel表會定期從.csv文件更新,因此我需要保留與工作編號鏈接的工作記錄副本,這會從表中刪除所有已完成的工作。
謝謝你的幫助
您應該首先創建一個名為Jobs的新工作表,然后使用如下結構:
Sheets("Jobs").Cells("coordinates here").Value = "your values"
也許您需要創建一個計數器,但這是另一個主題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.