使用 vba 用户表单值更新 Workday.intl 公式

问题描述 投票:0回答:1

我有一个工作日公式,可以根据一个月的持续时间计算日期。我希望用户在用户表单中设置该持续时间并将公式更新为该持续时间。我收到 1004 错误,但不确定原因。

单元格 F525 中的公式:

=WORKDAY.INTL(WORKDAY(F3,(26*22)),1,"0111111")

更新公式:

 =WORKDAY.INTL(WORKDAY(F3,(10*22)),1,"0111111")

Private Sub Calculate_CommandButton_Click()
    Sheets("Project Plan").Select
    Application.ScreenUpdating = False

    Dim lookupValue As String

    Dim targetCell As Range


    ' Get the value from the UserForm control

    lookupValue = Me.GoLiveDuration_TextBox.Value


    ' Set the target cell where the VLOOKUP formula is

    Set targetCell = Range("F525") ' Replace "A1" with the actual cell containing the formula


    ' Update the VLOOKUP formula with the new lookup value

    targetCell.Formula = "=WORKDAY.INTL(WORKDAY(F3,(" & lookupValue & " *22)),1, & Chr(34) 0111111 &   Chr(34) &) "
 

    Application.ScreenUpdating = True
End Sub
vba excel-2016 visio
1个回答
0
投票

这个:

targetCell.Formula = "=WORKDAY.INTL(WORKDAY(F3,(" & _
     lookupValue & " *22)),1, & Chr(34) 0111111 &   Chr(34) &) "

应该是

targetCell.Formula = "=WORKDAY.INTL(WORKDAY(F3,(" & _
     lookupValue & " *22)),1,""0111111"") "

您可以通过将引号加倍来转义引号

© www.soinside.com 2019 - 2024. All rights reserved.