Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default InSTR Compare erorr

I need a small adjustment to the following code.

(InStr(CStr(rangeArray(rIndex, 2)), testString) changed into
(InStr(CStr(rangeArray(rIndex, 2)), testString, 1) to get a case insensitve
textcompare. But it returns an error. What am I doing wrong?

The full code:

Function matchArray(ByVal testString As String, ByVal dataRange As Range,
Optional IndexNum As Long) As Variant
Dim outRRay() As String
Dim rangeArray As Variant
Dim xColl As New Collection
Dim xVal As Variant
Dim rIndex As Long

With dataRange.Parent
Set dataRange = Application.Intersect(dataRange, .UsedRange)
End With
With dataRange.Resize(, 3)
rangeArray = .Value
End With

For rIndex = 1 To UBound(rangeArray, 1)
If (InStr(CStr(rangeArray(rIndex, 2)), testString) 0) Or
(InStr(CStr(rangeArray(rIndex, 3)), testString) 0) Then
xVal = CStr(rangeArray(rIndex, 1))
On Error Resume Next
xColl.Add Item:=xVal, key:=xVal
On Error GoTo 0
End If
Next rIndex
ReDim outRRay(1 To Application.Max(Application.Caller.Cells.Count,
xColl.Count, IndexNum))

For rIndex = 1 To xColl.Count
outRRay(rIndex) = xColl(rIndex)
Next rIndex


If IndexNum < 1 Then
matchArray = outRRay
Else
matchArray = outRRay(IndexNum)
End If

End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default InSTR Compare erorr

I'm not getting an error with Excel 2003. I think it must have to do with
the data you are using. I tried forcing errors using different data patterns
but was not successful.

Try removing your data and working with a a few cell filled with data and
see if you can isolate where the problem is located.

"dakke" wrote:

I need a small adjustment to the following code.

(InStr(CStr(rangeArray(rIndex, 2)), testString) changed into
(InStr(CStr(rangeArray(rIndex, 2)), testString, 1) to get a case insensitve
textcompare. But it returns an error. What am I doing wrong?

The full code:

Function matchArray(ByVal testString As String, ByVal dataRange As Range,
Optional IndexNum As Long) As Variant
Dim outRRay() As String
Dim rangeArray As Variant
Dim xColl As New Collection
Dim xVal As Variant
Dim rIndex As Long

With dataRange.Parent
Set dataRange = Application.Intersect(dataRange, .UsedRange)
End With
With dataRange.Resize(, 3)
rangeArray = .Value
End With

For rIndex = 1 To UBound(rangeArray, 1)
If (InStr(CStr(rangeArray(rIndex, 2)), testString) 0) Or
(InStr(CStr(rangeArray(rIndex, 3)), testString) 0) Then
xVal = CStr(rangeArray(rIndex, 1))
On Error Resume Next
xColl.Add Item:=xVal, key:=xVal
On Error GoTo 0
End If
Next rIndex
ReDim outRRay(1 To Application.Max(Application.Caller.Cells.Count,
xColl.Count, IndexNum))

For rIndex = 1 To xColl.Count
outRRay(rIndex) = xColl(rIndex)
Next rIndex


If IndexNum < 1 Then
matchArray = outRRay
Else
matchArray = outRRay(IndexNum)
End If

End Function

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default InSTR Compare erorr

InStr is a strange function in that it has an optional first argument.
However, in order to make use of the compare argument, you **must** specify
the optional first argument. Try it this way...

InStr(1, CStr(rangeArray(rIndex, 2)), testString, 1)

By the way, it is more descriptive if you use the predefined constant for
the fourth argument...

InStr(1, CStr(rangeArray(rIndex, 2)), testString, vbTextCompare)

Rick


"dakke" wrote in message
...
I need a small adjustment to the following code.

(InStr(CStr(rangeArray(rIndex, 2)), testString) changed into
(InStr(CStr(rangeArray(rIndex, 2)), testString, 1) to get a case
insensitve
textcompare. But it returns an error. What am I doing wrong?

The full code:

Function matchArray(ByVal testString As String, ByVal dataRange As Range,
Optional IndexNum As Long) As Variant
Dim outRRay() As String
Dim rangeArray As Variant
Dim xColl As New Collection
Dim xVal As Variant
Dim rIndex As Long

With dataRange.Parent
Set dataRange = Application.Intersect(dataRange, .UsedRange)
End With
With dataRange.Resize(, 3)
rangeArray = .Value
End With

For rIndex = 1 To UBound(rangeArray, 1)
If (InStr(CStr(rangeArray(rIndex, 2)), testString) 0) Or
(InStr(CStr(rangeArray(rIndex, 3)), testString) 0) Then
xVal = CStr(rangeArray(rIndex, 1))
On Error Resume Next
xColl.Add Item:=xVal, key:=xVal
On Error GoTo 0
End If
Next rIndex
ReDim outRRay(1 To Application.Max(Application.Caller.Cells.Count,
xColl.Count, IndexNum))

For rIndex = 1 To xColl.Count
outRRay(rIndex) = xColl(rIndex)
Next rIndex


If IndexNum < 1 Then
matchArray = outRRay
Else
matchArray = outRRay(IndexNum)
End If

End Function


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default InSTR Compare erorr

That was spot on Rick.

Indeed I needed to add the first option too. Thanks a lot.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solver internal erorr message Rita968 Excel Discussion (Misc queries) 0 March 6th 09 08:48 PM
How to fix this erorr (Selected Collating sequence not support by theoperating system) sahm Excel Programming 1 November 22nd 07 12:00 PM
i have erorr on my email on yahoo why? [email protected] Excel Programming 1 May 30th 07 06:20 AM
Why is this an erorr? John Smith Excel Programming 1 December 1st 06 04:15 AM
Erorr when 'edit query' Johan Nilsson Excel Discussion (Misc queries) 0 February 8th 06 09:16 AM


All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"