简体   繁体   中英

Vbs Excel formula for copying target's formula to current cell

I am using an ETL for APPENDING automatically some rows in Excel, but unfortunately there is no way to grab styles and formulae from previous rows.

So I decided to insert new rows with the following hardcoded formula/Value:

=CopyFormula(INDIRECT(ADDRESS(ROW()-1;COLUMN())))

And then design CopyFormula as a UDF that simply copies formula from the passed target cell

Why is not something like this working?

Public Function CopyFormula(rng As Range)
    rng.Copy Destination:=ActiveCell
    'ActiveCell.Formula = rng.Formula
    'return no value
End Function

I also tried copying and evaluating the neighbors formula, but unfortunately, evaluate() does not work when INDIRECT is present in the formula http://support.microsoft.com/kb/131384

Any suggestion?

Use a Sub rather than a UDF

UDFs in worksheet cells can only return values, not modify other cells.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM