簡體   English   中英

如何將VBA粘貼到包含公式的單元格中

[英]How to have vba paste into a cell that contains a formula

如果在上一個線程中已經回答了這個問題,我深表歉意,我搜索了一段時間,但實際上不確定該怎么稱呼我遇到的問題。

我是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

但這會找到第一個完全空白的單元格,並避免其中包含任何公式。

反正有解決這個問題的方法嗎?

也許是這樣的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM