I have difficulty fixing the following problem I am facing:
Lets say I have this code
i_GroupNumberA = Application.WorksheetFunction.CountIf(Sheets("SheetX").Range("G2:G500"), "Red")
i_GroupNumberB = Application.WorksheetFunction.CountIf(Sheets("SheetX").Range("G2:G500"), "Green")
For i = 2 To LastRow
For j = 2 To LastCol
groupNumber = Sheets("Sheet1").Cells(i, j).Value
i_GroupNumberA = 35 'this number a integer that I have got from a cells.value
i_GroupNumberB = 39
If groupNumber = Sheets("Sheet1").Cells(i, j).Value Then
i_Variable = "i_" + groupNumber + "AlphabeticLetter"
MsgBox i_Variable
End If
Next j
Next i
As a result I get i_Variable as a string in a messagebox as an outcome:
i_groupNumberA
I want to have the following result:
35
What I am asking is how can I make get a new variable of a string functioning as a integer.
I am not sure if I am asking this right?
I did as @engineersmnky said, but no effect. I check sites and made some adjustments together with your code. But Still I can't get the needed number in return. So far I got this:
Dim Group As New Collection
i_GroupNumberA = Application.WorksheetFunction.CountIf(Sheets("SheetX").Range("G2:G500"), "Red") 'lets assume it is an number 35
i_GroupNumberB = Application.WorksheetFunction.CountIf(Sheets("SheetX").Range("G2:G500"), "Green") 'lets assume it is an number 39
Group.Add i_GroupNumberA
Group.Add i_GroupNumberB
For i = 2 To LastRow
For j = 2 To LastCol
groupNumber = Sheets("Sheet1").Cells(i, j).Value
i_Variable = "i_" + groupNumber + "AlphabeticLetter"
Group(i_Variable)
Next j
Next i
Group(i_variable) I cant figure it out? for some reason it is not working.