Custom function not recognising strings as arguments

ny248

New Member
Joined
Jan 23, 2016
Messages
4
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
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Could you post the code for the custom function.
Have you tried

Code:
If Custom_Function(CStr(cells(i+1,1).value), CStr(cells(i+1,1).offset(-j,0).value)) Then
 
Upvote 0
Hi mikerickson - thanks so much for the response, that has solved the problem. Greatly appreciated!
 
Upvote 0

Forum statistics

Threads
1,215,361
Messages
6,124,497
Members
449,166
Latest member
hokjock

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top