将公式复制到另一个工作表并将其作为值粘贴到特定列

时间:2018-03-16 00:03:39

标签: excel vba excel-vba

每当我尝试运行此代码时,我都遇到了麻烦。它工作正常,但当其他列为空时,它会连续运行公式。如果下一列为空,则必须停止运行公式。我如何使用现有代码执行此操作。谢谢你 请参阅下面的代码。

     Sub L4FORMULA()
     Dim rngFor As Range
     Dim RNG1 As Range
     Dim LastRow As Long

     Application.Calculation = xlCalculationManual
     Set rngFor = Sheet2.Range("P2")
     Set RNG1 = Sheet2.Range("U2")

    Sheet4.Activate

    LastRow = Application.WorksheetFunction.CountA(Sheet1.Range("B:B"))

    rngFor.Copy Sheet4.Range("P2:P" & LastRow)
    Sheet4.Range("P2:P" & LastRow).Calculate
        Sheet4.Range("P2:P" & LastRow).Value = Sheet4.Range("P2:P" & LastRow).Value

    RNG1.Copy Sheet4.Range("U2:U" & LastRow)
    Sheet4.Range("U2:U" & LastRow).Calculate
        Sheet4.Range("U2:U" & LastRow).Value = Sheet4.Range("U2:U" & LastRow).Value

   Application.Calculation = xlCalculationAutomatic
   End Sub

1 个答案:

答案 0 :(得分:0)

我已经解决了我的问题,我只是替换Lastrow声明的范围。 感谢您的帮助。

<div *ngIf="state!='canceled'"|| state!='open'  > something </div>
相关问题