简体   繁体   中英

how to assign the formula on cell depending on the value of the differnt sheet in vba

I am trying write a VBA script for the summary report I have multiple sheets in the first sheet I have summary report below calculations I need to do in loop for multiple sheets

Sheets("Dashboard").Select
Range("D5").Select
Selection.Formula = "=COUNTIF(Sheet2!E:E,""Passed"")"

Like above I have multiple formulas to apply on cell and I don't want to write the formula for each sheet Any suggestions plz

Here is how you loop thru all the worksheets in a workbook: (avoid using Select )

  Dim sh As Worksheet
  For Each sh In ActiveWorkbook.Worksheets
    If sh.Name <> "NameOfSheet" Then
      sh.Range("D5").Formula = "=COUNTIF('" & sh.Name & "'!E:E,""Passed"")"
    End If
  Next

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