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 > VBA code to find a value in a cell

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-29-06, 02:39
dbforums098 dbforums098 is offline
Registered User
 
Join Date: Jul 2004
Posts: 11
VBA code to find a value in a cell

Hi,
I have a list in excel as follows:

Vendor/InvNbr/InvDate/InvAmt/check

I want to create a VBA code to prompt the user to input the value to find and then go to the row and put "paid" in the check column if the value is found. If not, display a message back to the user.

Can someone help me write the VBA code?

Thank you very much
Reply With Quote
  #2 (permalink)  
Old 07-29-06, 12:35
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 533
One way to do this is using a input box to prompt the user for a value then use the 'Find' method to search the entire sheet or a defined range. Another way to search the values would be to use a Loop to check each cell in a column, then exit the loop when a match is found.

This is an example I adapted from code I use which uses the 'Find' method.
Code:
Sub FindInput()
    Dim stringToFind As String
    Dim Found As Range
    
    stringToFind = Application.InputBox("Enter invoice Number to find?", _
    "Search String")
    
    If Trim(stringToFind) = "" Then Exit Sub
    
    Set Found = Cells.Find(What:=stringToFind, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext _
        , MatchCase:=False)
    
    If Found Is Nothing Then
    Else
        With Found
            .Activate
            If Not Len(.offset(rowOffset:=0, columnOffset:=1)) = 0 Then
                    .offset(rowOffset:=0, columnOffset:=2) = "paid"
            Else
            ' here I would just activate the cell insted of showing a message
                    msgbox "The value does not Exist"
            End If    
        End With
     End If   
End Sub
__________________
~

Bill
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