Results 1 to 6 of 6

Find String in Range and Select it - unexpected results

Threaded View

  1. #1
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Find String in Range and Select it - unexpected results

    Hi,

    Hoping someone might be able to shed some light on an annomaly I've come across when finding a string in a specified range. I have found a workaround but not really happy with it and want to understand why Excel / VBA is behaving this way as it's not as I would expect. I'm using Excel 2003.

    The following code is a simplified version of what I'm using within a bigger project:

    Dim fxRng, fxRngAdd
    Dim FindString As String
    
    FindString = FXForm1.Controls("Textbox1").Value
                
                    With Sheets("Sheet1").Range("B6:B170")
                        Set fxRng = .Find(What:=FindString, After:=.Cells(.Cells.Count), LookIn:=xlValues, LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) 
                        If Not fxRng Is Nothing Then 
                            fxRngAdd = fxRng.Address
                            .Range(fxRngAdd).Select
                        End If
                    End With
    The FindString will be a currency (e.g. "EUR") which I want it to find within the range B6:B170 specifically. As I step through the fxRng variable displays "EUR" and the fxRngAdd variable shows $B$6 when I hover the mouse over it. However when it's selected, the cell C11 is the one that's actually selected not B6!?!
    I can work around this by changing the Range to "B:B" where it selects C6 instead of B6 then offset back one, but I'd really rather not do it this way - just seems clumsy.

    Anyone have any ideas why it's behaving this way? Have I done something dumb in the .Find bit or setting the variables?

    Any help appreciated - bugging me.

    **EDIT** Added Example Workbook

    Thanks, TC
    Attached Files Attached Files
    Last edited by TC1980; 06-03-2013 at 07:32 AM. Reason: Adding Workbook Example

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1