2015-10-26 102 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

你是个天才蒂姆。 –

相关问题