首页 文章

Excel VBA将单元格数据保存到单独的工作表中

提问于
浏览
2

如何将工作表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文件更新,从表中删除任何已完成的作业 .

谢谢你的帮助

1 回答

  • 0

    您应该首先创建一个名为 Jobs 的新工作表,然后使用如下构造:

    Sheets("Jobs").Cells("coordinates here").Value = "your values"
    

    也许你需要创建一个计数器,但那是另一个主题 .

相关问题