kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Code:
Private Sub CmbName_Change()
With Sheets("Sheet1")
Dim i As Long, j As Long
For i = 5 To 9
Select Case .CmbQuest.ListIndex
Case 0: .Cells(2, i + 4) = Application.CountIfs(.[D5:D15], .CmbName, .[I5:I15], i - 4) / Application.CountIf(.[D5:D15], .CmbName)
Case 1: .Cells(2, i + 4) = Application.CountIfs(.[D5:D15], .CmbName, .[J5:J15], i - 4) / Application.CountIf(.[D5:D15], .CmbName)
Case 2: .Cells(2, i + 4) = Application.CountIfs(.[D5:D15], .CmbName, .[K5:K15], i - 4) / Application.CountIf(.[D5:D15], .CmbName)
Case 3: .Cells(2, i + 4) = Application.CountIfs(.[D5:D15], .CmbName, .[L5:L15], i - 4) / Application.CountIf(.[D5:D15], .CmbName)
Case 4: .Cells(2, i + 4) = Application.CountIfs(.[D5:D15], .CmbName, .[M5:M15], i - 4) / Application.CountIf(.[D5:D15], .CmbName)
Case 5: .Cells(2, i + 4) = Application.CountIfs(.[D5:D15], .CmbName, .[N5:N15], i - 4) / Application.CountIf(.[D5:D15], .CmbName)
Case 6: .Cells(2, i + 4) = Application.CountIfs(.[D5:D15], .CmbName, .[O5:O15], i - 4) / Application.CountIf(.[D5:D15], .CmbName)
End Select
Next i
End With
End Sub
I wanted to avoid the case statement and use a loop to switch the columns but it keeps telling me type mismatch .
Example
Code:
.Cells(2, i + 4) = Application.CountIfs(.[D5:D15], .CmbName, .Range(.Cells(5, .CmbQuest.ListIndex + 9), .Cells(15, .CmbQuest.ListIndex + 9)), i - 4) / Application.CountIf(.[D5:D15], .CmbName)
How can I bypass that error?