If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Help with FIND function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-10-09, 10:11
UNCC-EE UNCC-EE is offline
Registered User
 
Join Date: Feb 2009
Posts: 47
Help with FIND function

I am trying to find a user enterd percentage like 97% or 89% in a row of data.

Dim ReportValue As String
ReportValue = Application.InputBox("Enter Report Value in XX% format")
ActiveCell.select
ActiveCell.EntireRow.Select
Selection.Find(What:=ReportValue, After:=ActiveCell, LookIn:=xlFormulas,
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Select


Compiler keeps giving me errors I save the value as a string but it doesnt work.
Reply With Quote
  #2 (permalink)  
Old 04-13-09, 12:24
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
Hi,

The first line of your code is missing a line break.

Also, it would be better to defensively code to allow for the chance that the range object's find method doesn't find a cell containing the value you are looking for. Typically we do this using an intermediary range object variable which we can test:

Code:
Sub foo()
    Dim ReportValue As String, rngFound As Range
    
    ReportValue = Application.InputBox("Enter Report Value in XX% format")
    
    Set rngFound = ActiveCell.EntireRow.Find( _
                    What:=ReportValue, _
                    After:=ActiveCell, _
                    LookIn:=xlFormulas, _
                    LookAt:=xlPart, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlNext, _
                    MatchCase:=False, _
                    SearchFormat:=False)
                    
    'did we find anything?
    If rngFound Is Nothing Then
        MsgBox "Report value not found...."
    Else
        rngFound.Select
    End If

End Sub
Hope that helps...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On