I would like to ask whether in VBA in Excel there is a possibility to store a part of the code for example inside in string, what I mean is shown in the example below (this code doesn't work):
Sub newMacro()
Dim wb As Workbook
Dim ws As Worksheet
Dim sAdditional As String
Dim rngWhereCount_1 As Range
Dim rngWhereCount_2 As Range
Dim iCellValue As Integer
Dim i as integer
Set wb = ThisWorkbook
Set ws = wb.Worksheets(1)
Set rngWhereCount_1 = ws.Columns(1)
Set rngWhereCount_2 = ws.Columns(2)
For i = 1 To 10
If (i = 1) Or (i = 2) Then
sAdditional = ", rngWhereCount_2, i"
Else
sAdditional = ""
End If
iCellValue = Application.WorksheetFunction.CountIfs(rngWhereCount_1, 1 & sAdditional)
Next i
End Sub
So the question is if there is an easy and clever way to declare sAdditional (maybe not as string), but to make it optional inside the loop, and at the same time sAdditional contains Range and string inside...
Thanks in advance! P.
CountIffunction takes in aRangeand aRangetakes in aStringso there might be something to that there... cause you can store extra ranges asStringsand just callRange(strValue)...sAdditionalis not alwaysRangeorString, but the combination of these two.