Hi everyone
I have written a custom function that takes 2 arguments as strings - when the function is called ordinarily it works absolutely fine.
However, when I call it within a double-loop it does not recognise the strings in the cells - I have tested the loop using a counter and know it works as expected. To summarise, the loop moves down a column and then loops back up and is supposed to compare the string in the starting cell to the string in the cell above. If the comparison is TRUE then it should exit.
If anyone can help in telling me why the strings are not recognised it would be greatly appreciated. Alternatively, can a function that takes strings as arguments be applied to a range?
Many thanks in advance!
Code:
Sub Loop_Design()
Dim length As Integer 'length of the loop
'NOTE: cells argument should be used to get strings
Dim counter As Integer 'counter to increment the length of the loop every
time there is another comparison
length = 50
counter = 1
'set up the loop
For i = 1 To length 'initialise the outer loop
For j = 1 To counter
If Custom_Function(cells(i+1,1).value,cells(i+1,1).offset(-j,0).value) = True Then
cells(i+1,1).offset(0,1) = "Match"
Exit for
End If
Next j
counter = counter + 1 'increment inner loop because there is now one another comparison to make
Next i
End Sub
I have written a custom function that takes 2 arguments as strings - when the function is called ordinarily it works absolutely fine.
However, when I call it within a double-loop it does not recognise the strings in the cells - I have tested the loop using a counter and know it works as expected. To summarise, the loop moves down a column and then loops back up and is supposed to compare the string in the starting cell to the string in the cell above. If the comparison is TRUE then it should exit.
If anyone can help in telling me why the strings are not recognised it would be greatly appreciated. Alternatively, can a function that takes strings as arguments be applied to a range?
Many thanks in advance!
Code:
Sub Loop_Design()
Dim length As Integer 'length of the loop
'NOTE: cells argument should be used to get strings
Dim counter As Integer 'counter to increment the length of the loop every
time there is another comparison
length = 50
counter = 1
'set up the loop
For i = 1 To length 'initialise the outer loop
For j = 1 To counter
If Custom_Function(cells(i+1,1).value,cells(i+1,1).offset(-j,0).value) = True Then
cells(i+1,1).offset(0,1) = "Match"
Exit for
End If
Next j
counter = counter + 1 'increment inner loop because there is now one another comparison to make
Next i
End Sub