[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Modifying VBA Search Code

Posted on 2011-03-21
2
Medium Priority
?
360 Views
Last Modified: 2013-11-27
I have the following code in use on a userform within my workbook.

Basically it searches by a particular column for a numeric value and then pouplates the userform with the contents of that row.

Private Sub cmdSearch_Click()
   Dim rw As Long             'row the search value was found on
   Dim myVal As Long          'converted search value
 
   On Error Resume Next
      'validate user input
      If txtSearch.Value = "" Or _
         Not IsNumeric(CLng(txtSearch.Value)) Then
         MsgBox "Enter valid SIR number!"
         txtSearch.SetFocus
         Exit Sub
      End If
 
      'convert the TexBox value to  data type long and get row number
      myVal = CLng(txtSearch.Value)
      On Error Resume Next
 
       With Sheets("SIRs").Range("C:C")
         Set cell = .Find(myVal, LookIn:=xlValues)
         rw = cell.Row
       End With
   On Error GoTo 0

   On Error GoTo 0
   If rw = 0 Then
      MsgBox "SIR Not Found"
   Else
      Call PopulateTextBoxes(rw)
   End If
End Sub

Open in new window


I now want to create a new search function whereby it searches another column (E) but for a non-numeric value this time. Naively I assumed I could copy the above code, tailor it for column E and remove the following piece of code

Or _
         Not IsNumeric(CLng(txtSearch.Value)) 

Open in new window


Unfortunately it keeps returning a 'SIR not Found' result.

can anyone help please?
0
Comment
Question by:laffs_efc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
Pr1z earned 500 total points
ID: 35182763
Line 3 defines a data type of Long ==> change that to string
Line 15 is a cast to a long numeric data type ==> use cstr() or simply(trim()

Hope that helps

Priz
0
 

Author Comment

by:laffs_efc
ID: 35188619
Awesome! Cheers Pr1z!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question