每次点击提交时,使用Excel用户窗体动态添加公式

时间:2019-07-10 20:51:43

标签: excel vba

这是我用于“提交”按钮的代码

Private Sub cbsubmit_Click()
Dim emptyRow As Long
Sheets("ComplaintsData").Activate
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
Cells(emptyRow, 2).Value = emptyRow - 1
Cells(emptyRow, 1).Value = dtdate.Value
Cells(emptyRow, 3).Value = cmbSource.Value
Cells(emptyRow, 4).Value = cmbIssue.Value
Cells(emptyRow, 5).Value = cmbcomptype.ValueC
Cells(emptyRow, 6).Value = tbname.Value
Cells(emptyRow, 7).Value = ccdemail.Value
Cells(emptyRow, 8).Value = ccdphone.Value
Cells(emptyRow, 9).Value = cmbRegion.Value
Cells(emptyRow, 10).Value = tbreferred.Value
Cells(emptyRow, 11).Value = tbmanaged.Value
Cells(emptyRow, 12).Value = tbaction.Value
Cells(emptyRow, 13).Value = tbObjLink.Value
Cells(emptyRow, 14).Formula = "=TEXT(DATE(YEAR(emptyrow,1),MONTH(emptyrow,1),DAY(emptyrow,1)),""mmm""& "" "" & ""yyyy"")"

一切正常,直到我要添加公式的位置为止。我需要的是每次单击提交时,都会根据A列及其关联的行的日期在N列中填充该公式。

希望有人可以帮助我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

类似这样的东西:

Cells(emptyRow, 14).Formula = "=TEXT(A" & emptyRow & ", ""mmm yyyy"")"

如果ColA中的值已经是日期,则无需使用DAY / MONTH / YEAR来重建它