Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
Go Back  Xtreme Visual Basic Talk > > > Bug when using Excel Find method in .NET


Reply
 
Thread Tools Display Modes
  #1  
Old 05-02-2013, 05:01 AM
Shankar_R Shankar_R is offline
Newcomer
 
Join Date: Mar 2013
Posts: 4
Default Bug when using Excel Find method in .NET


Hi,

I am observing a bug when I use the Find method on a range having a single cell with the value in it matching the target of the Find. If there are other cells under that cell which have the same value, the find returns the first such cell even though it is outside the range.

The Find method is supposed to look only at cells in the range, not any outside. When the last cell of the range is reached, it simply wraps around. This is the case in VBA, but in VB.NET I am finding that it looks at other cells.

Anyone else noticed this aberrant behavior?

Shankar
Reply With Quote
  #2  
Old 05-02-2013, 06:03 AM
Shankar_R Shankar_R is offline
Newcomer
 
Join Date: Mar 2013
Posts: 4
Default

Here is a sample VB.NET code which demonstrates the bug-
PHP Code:
Imports Excel Microsoft.Office.Interop.Excel
Imports System
.Runtime.InteropServices

Module Module1
    Dim XlApp 
As Excel.Application

    Sub Main
()
        Try
            
XlApp = New Excel.Application
            FindInSingleCell
()
        Catch 
Ex As Exception
            MsgBox
(Ex.Message)
        
Finally
            GC
.Collect()
            
GC.WaitForPendingFinalizers()
            
GC.Collect()
            
GC.WaitForPendingFinalizers()
            
Marshal.FinalReleaseComObject(XlApp)
        
End Try
    
End Sub



    Sub FindInSingleCell
()
        
Dim Wkb As Excel.WorkbookWks As Excel.Worksheet
        Dim A1 
As Excel.RangeMatchCell As Excel.Range

        Wkb 
XlApp.Workbooks.Add
        Wks 
CType(Wkb.Sheets("Sheet1"), Excel.Worksheet)

        
With Wks
            
.Cells(11) = "Hi" 'cell A1
            .Cells(3, 1) = "Hi" '
cell A3
        End With

        A1 
CType(Wks.Cells(11), Excel.Range)
        
MatchCell A1.Find("Hi"LookAt:=Excel.XlLookAt.xlWhole'search should be restricted to only cell A1

        If Not MatchCell Is Nothing Then
            MsgBox("Matchcell has row = " & CStr(MatchCell.Row) & " and col = " & CStr(MatchCell.Column))
        Else
            MsgBox("No match found")
        End If
        Wkb.Close(SaveChanges:=False)
    End Sub


End Module 
The range A1 is a single cell and the Find method has to only return that cell. However, it returns A3. The message is "Matchcell has row = 3 and col = 1".

The equivalent sub in VBA correctly returns A1 however.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
 
Bug when using Excel Find method in .NET
Bug when using Excel Find method in .NET
 
-->