I would like to use a named ranged using the countifs function, and not using a specific range using the name of column and the number of rows (because on my different sheets, the columns and rows are never the same).
Here is my code:
Sub ClearFULLandPART()
'
' test Macro
'
'
Dim rgn As Range
Dim x As Long, y As Long
Cells.Find(What:="TOTAL AIRLANES FULL SERVICE", After:=ActiveCell, LookIn _
:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection _
:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.EntireRow.Select
Selection.ClearContents
ActiveSheet.Cells(ActiveCell.Row, 1).Select
ActiveCell.Value = "TOTAL AIRLANES FULL SERVICE"
Range("JB3").Select
Cells.Find(What:="TOTAL AIRLANES PART SERVICE", After:=ActiveCell, LookIn _
:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection _
:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.EntireRow.Select
Selection.ClearContents
ActiveSheet.Cells(ActiveCell.Row, 1).Select
ActiveCell.Value = "TOTAL AIRLANES PART SERVICE"
'Selectionne la cellule Cargoflight, Total Airlanes Part Service
ActiveCell.Select
ActiveCell.Offset(0, 7).Select
Do Until ActiveCell.EntireColumn.Hidden = False
ActiveCell.Offset(0, 7).Select
Loop
'définition des ranges avec maintained et information
'Set rgn = ActiveCell.EntireColumn.Resize(Rows.Count - 2).Offset(2)
'rgn.Select
Cells.Find(What:="TOTAL AIRLANES PART SERVICE", After:=ActiveCell, LookIn _
:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection _
:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Select
ActiveCell.Select
ActiveCell.Offset(0, 7).Select
Do Until ActiveCell.EntireColumn.Hidden = False
ActiveCell.Offset(0, 7).Select
Loop
Dim rng1 As Range
Set rgn1 = Cells(2, ActiveCell.Column)
Dim rgn2 As Range
' -1 to select the cell of how many row above current cell
Set rgn2 = Cells(ActiveCell.Row - 1, ActiveCell.Column)
Dim rgnfrom1to2 As Range
Set rgnfrom1to2 = Range(rgn1, rgn2)
'end of selection of the column to current cell row-1
Dim rangeEG2EG9 As Range
Set rangeEG2EG9 = Range("EG2:EG9")
'HERE IS THE PROBLEM
**ActiveCell.Value = WorksheetFunction.CountIfs(rgnfrom1to2, "maintained", Range("EG2:EG9"), "")**
'I would like to do the above function to the next 3 countsif using the rgnfrom1to2
ActiveCell.Select
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = WorksheetFunction.CountIfs(Range("EE2:EE9"), "maintained", Range("EG2:EG9"), "")
ActiveCell.Select
ActiveCell.Offset(-1, 0).Select
ActiveCell.Value = WorksheetFunction.CountIfs(Range("EE2:EE9"), "maintained", Range("EG2:EG9"), "*")
ActiveCell.Select
ActiveCell.Offset(0, -1).Select
ActiveCell.Value = WorksheetFunction.CountIfs(Range("EE2:EE9"), "maintained", Range("EG2:EG9"), "*")
End Sub
I get an error each time I try this function:
ActiveCell.Value = WorksheetFunction.CountIfs(rgnfrom1to2, "maintained", Range("EG2:EG9"), "")