I have one worksheet (Daily) with data in columns and a header. The data is dynamic based on the number of days in a month and it has been conditionally formatted to icons (Incomplete = T, Complete = R). I'm trying to create a chart on another worksheet (WS2) to show the percent complete and incomplete for each item (header).
I have a table on a 3rd worksheet (WS3) to count all non-empty cells in each column, countif "T", and countif "R". (eg. =COUNTIF(Daily!D5:D29,"R")). The chart on WS1 selects data from WS3 for each item. Sometimes I have to add or delete a column on the Daily page. I'm trying to write a sub to loop through each column on Daily using CountIF and CountA and show the results on WS2.
Sub LoopforCt()
Dim ws As Worksheet
Dim Daily As Worksheet
Dim Test As Worksheet
Dim AllData As Variant
Dim pcv As Range
Set Daily = Sheets("Daily")
Set Test = Sheets("Test")
Set AllData = Daily.Range("B5:B100")
Set pcv = Test.Range("A22")
With AllData
pcv = "=COUNTIF(Daily!C5:C29,""R"")"
End With
End Sub
I've been able to get the countif to work for the first column, but I'm lost on how to put this in a loop. I want to continue to CountIf for the next column's results in Test.Range("B22"), etc.
Thank you!
B22
be set to"=COUNTIF(Daily!D5:D29,""R"")"
? You can write a formula with relative references to an entire range, no need to loop column by column. – BigBenpcv
should be the entire range - not justA22
butA22:X22
or whatever column. Thenpcv.Formula = "=COUNTIF(Daily!C5:C29,""R"")"
. – BigBen