2017-10-20 62 views
2

我将如何保存从工作表1我的手机数据到工作表2.Excel的VBA细胞数据保存到不同的片

基本上我有这样的一个表: -

   | 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文件更新,因此我需要保留与作业编号链接的作业备注副本,这样可以从表格中删除所有已完成的作业。

感谢所有帮助

回答

0

,必须先创建一个名为像乔布斯新的工作表,然后使用结构是这样的:

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

也许你将需要创建一个计数器,但是这一些其他话题。

+0

感谢您设计的信息,现在我可以搜索工作号码,并检查它是否存在,如果不添加到新工作表或更新它。 – kiper3000