2015-10-26 101 views
0

如果已在上一個線程中回答了此問題,我表示歉意,我搜索了一段時間,但確實不確定怎麼稱呼我遇到的問題。如何將vba粘貼到包含公式的單元格中

我對VBA很新,這是我第一次真正進入VBA。

我有一個VBA問題,將表單的內容粘貼到電子表格中,在第一列中有一個vlookup引用列的電子表格(工作表需要有表單的excel查找,因此需要該引用)

我目前使用一個按鈕: -

Private Sub submit_Click() 
Dim RowCount As Long 
RowCount = Worksheets("Raw Data").Range("B1").CurrentRegion.Rows.Count 
Private Sub submit_Click() 

With Worksheets("Raw Data").Range("B1") 
.Offset(RowCount, 0).Value = Format(Now, "dd/mm/yyyy") 
.Offset(RowCount, 1).Value = Me.operator.Value 
.Offset(RowCount, 2).Value = Me.custexp.Value 
.Offset(RowCount, 3).Value = Me.fcr.Value 
.Offset(RowCount, 4).Value = Me.opfcr.Value 
.Offset(RowCount, 5).Value = Me.compliant.Value 
.Offset(RowCount, 6).Value = Me.summary.Value 
.Offset(RowCount, 7).Value = Me.evaluation.Value 
.Offset(RowCount, 8).Value = Me.compliance.Value 
.Offset(RowCount, 9).Value = Me.callid.Value 
.Offset(RowCount, 10).Value = Me.calltime.Value 
.Offset(RowCount, 11).Value = Me.leader.Value 
.Offset(RowCount, 12).Value = Me.custnum.Value 
End With 

Dim ctl As Control 

End Sub 

但這找到的第一個完全空白單元格,並避免了與公式中任何事情。

有沒有辦法解決這個問題?

+0

你需要表現出更多的代碼。 –

回答

0

也許是這樣的:

Private Sub submit_Click() 
    Dim c As Range 
    'find first empty cell in ColB (looking from the bottom of the sheet) 
    Set c = Worksheets("Raw Data").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0) 

    With c.EntireRow 
     .Cells(2).Value = Format(Now, "dd/mm/yyyy") 
     .Cells(3).Value = Me.Operator.Value 
     .Cells(4).Value = Me.custexp.Value 
     .Cells(5).Value = Me.fcr.Value 
     .Cells(6).Value = Me.opfcr.Value 
     .Cells(7).Value = Me.compliant.Value 
     .Cells(8).Value = Me.Summary.Value 
     .Cells(9).Value = Me.evaluation.Value 
     .Cells(10).Value = Me.compliance.Value 
     .Cells(11).Value = Me.callid.Value 
     .Cells(12).Value = Me.calltime.Value 
     .Cells(13).Value = Me.leader.Value 
     .Cells(14).Value = Me.custnum.Value 
    End With 

End Sub 
+0

你是個天才蒂姆。 –

相關問題