简体   繁体   中英

excel vba apply formula for all cells

I am new to macros. I have few routine works which I can automate using macros. First step is to apply clean formula for all cells (entire sheet). I tried recording macro option. It works for only one file. I am unable to determine range function for entire data. Any idea or suggestion is appreciable.

How can I change the number below one

ActiveCell.Formula2R1C1 = "=CLEAN(Sheet1!RC:R[54234]C[21])"

Below is sample code.

    Sheets.Add After:=ActiveSheet
    Range("A1").Select
    ActiveCell.Formula2R1C1 = "=CLEAN(Sheet1!C.End(xlDown))"

You don't need to select the range in order to address it. The following formula will do.

    Range("A1").Formula2R1C1 = "=CLEAN(Sheet1!C1:C" & Sheet1.Cells(1, 3).End(xlDown).Row & ")"

You may use Range("C3") in place of Cells(3, 1) if you prefer. However, if you expect to copy everything in the referenced column C then this line will do the same job.

Range("A1").Formula2R1C1 = "=CLEAN(Sheet1!C:C)"

There doesn't seem to be a good reason for using FormulaR1C1 here in place of the plain Formula property. Moreover, neither of the above formulas copied the entire range for me reliably because Excel inserts the spill-preventer @ into the formula most of the time. Therefore I recommend the indirect use of CLEAN() and paste values to the new sheet that are already "cleaned".

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