Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
773 views
in Technique[技术] by (71.8m points)

vba - Changing the formula of cell in all the sheets of the archive

I have an Excel archive that contains about 100 sheets i want write VBA macro so that cell A1 of each sheet will contain this formula:

=RECHERCHEV(B2;'SUMUP'!B$1:H478;3;FAUX)

This is my macro

Sub WorksheetLoop()

     ' Declare Current as a worksheet object variable.
     Dim Current As Worksheet

     ' Loop through all of the worksheets in the active workbook.
     For Each Current In Worksheets

     'Change the formula of cell A1 
        Current.Range("A1").Formula ="=RECHERCHEV(B2;'SUMUP'!B$1:H478;3;FAUX)"
     Next
End Sub

When i execute this macro i got error of execution '1004', Note that SUMUP is a sheet of my archive

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

VBA is very EN-US-centric. The Range.Formula property expects input as EN-US; you can use the Range.FormulaLocal property if you want to use the non-EN-US Office language pack FR-FR regionals.

Use one of these:

Current.Range("A1").Formula = "=VLOOKUP(B2,'SUMUP'!B$1:H478, 3, False)"
Current.Range("A1").FormulaLocal = "=RECHERCHEV(B2;'SUMUP'!B$1:H478;3;FAUX)"

Current.Range("A1").FormulaLocal = "=REMPLACER(CELLULE(""filename"";A1);1;TROUVE(""]"";CELLULE(""filename"";A1));"""")"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...