I am using this code in a very large vb project, but I isolated the problem area:
I am able to easily define CondCount1 early on, but when I try to do a loop later in the process to look through many different "CondCount"s I can not seem to get the code to find the value of the "CondCount & i".
In this case, I get "0" for each value of AssignCount as it passes through the loop even though the "vCondCount" is = "CondCount1" and using Val() function to find value of "vCondCount"
Any ideas how to make that "AssignCount" = value of "CondCount1" and then it loop to "CondCount2"....etc.?
Code:
Sub Test()
Dim CondCount1 As Integer
Dim CondCount2 As Integer
Dim vCondCount As String
Dim AssignCount As Integer
CondCount1 = 26
CondCount2 = 30
For i = 1 To Worksheets.Count - 1 Step 1
With Range("C" & 5 + i)
.NumberFormat = General
.Value = "Condition " & i
End With
vCondCount = "CondCount" & i
AssignCount = Val(vCondCount)
With Range("D" & 5 + i)
.NumberFormat = 0
.Value = AssignCount
End With
Next i
End Sub
I am able to easily define CondCount1 early on, but when I try to do a loop later in the process to look through many different "CondCount"s I can not seem to get the code to find the value of the "CondCount & i".
In this case, I get "0" for each value of AssignCount as it passes through the loop even though the "vCondCount" is = "CondCount1" and using Val() function to find value of "vCondCount"
Any ideas how to make that "AssignCount" = value of "CondCount1" and then it loop to "CondCount2"....etc.?