Getting Excel to refresh data on sheet from within VBA

前端 未结 6 1083
夕颜
夕颜 2020-11-27 06:14

How do you get spreadsheet data in Excel to recalculate itself from within VBA, without the kluge of just changing a cell value?

6条回答
  •  爱一瞬间的悲伤
    2020-11-27 06:33

    After a data connection update, some UDF's were not executing. Using a subroutine, I was trying to recalcuate a single column with:

    Sheets("mysheet").Columns("D").Calculate
    

    But above statement had no effect. None of above solutions helped, except kambeeks suggestion to replace formulas worked and was fast if manual recalc turned on during update. Below code solved my problem, even if not exactly responsible to OP "kluge" comment, it provided a fast/reliable solution to force recalculation of user-specified cells.

    Application.Calculation = xlManual
    DoEvents
    For Each mycell In Sheets("mysheet").Range("D9:D750").Cells
        mycell.Formula = mycell.Formula
    Next
    DoEvents
    Application.Calculation = xlAutomatic
    

提交回复
热议问题