2017-10-21 46 views
0

我在一张名为“Data”和“Daily”的工作簿中工作。我只是希望我的代码在日常工作表中保存新的输入,但不是这样做,而是保存在活动工作表中。如果有人能解决此问题,我将不胜感激。如何避免我的编码不保存活动工作表上的数据?

这里是我的代码:

Private Sub CommandButton1_Click() 'Saving Button 
    Dim sonsat As Long 

    sonsat = Sheets("Daily").Cells(Rows.Count, 1).End(xlUp).Row + 1 
    Call Main 'Progress Bar 

    Cells(sonsat, 1) = TextBox1 
    Cells(sonsat, 2) = TextBox2 
    Cells(sonsat, 3) = TextBox3 
    Cells(sonsat, 4) = TextBox4 
    Cells(sonsat, 5) = TextBox5 

    MsgBox "Registration is successful" 
    ListBox1.List = Sheets("Daily").Range("A2:E" & Cells(Rows.Count, 1).End(xlUp).Row).Value 'For refresh listbox 
    TextBox14.Value = ListBox1.ListCount 
End Sub 

回答

1

尝试以这种方式添加参考报表:

With Sheets("Daily") 
    .Cells(sonsat, 1) = TextBox1 'dot at the beginning is very important... 
    .Cells(sonsat, 2) = TextBox2 
    .Cells(sonsat, 3) = TextBox3 
    .Cells(sonsat, 4) = TextBox4 
    .Cells(sonsat, 5) = TextBox5 
end with 
+0

谢谢你亲爱的:) – Yasir