Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using Input Bx to Find Record

I got this code to work and find a record in a range of data and select that
row. But it only finds numbers. I need it to find a string, or a letter-
number combination. What do I need to change?

Private Sub CommandButton6_Click()
ActiveSheet.Unprotect
Dim rngOrder As Range
Dim lngReferenceNumber As Long

lngReferenceNumber = Application.InputBox( _
Prompt:="Enter P.O. Number", _
Title:="Enter P.O. Number", _
Type:=1)

Set rngOrder = Worksheets("PO's").Range("A:A").Find( _
what:=lngReferenceNumber, _
lookat:=xlWhole)

If rngOrder Is Nothing Then
MsgBox "P.O. not found"
ActiveSheet.Protect
Else
With rngOrder
.Activate
Selection.Offset(0, 1).Select


End With
End If


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Using Input Bx to Find Record

One way:

Private Sub CommandButton6_Click()
Dim rngOrder As Range
Dim strReferenceNumber As String

strReferenceNumber = Application.InputBox( _
Prompt:="Enter P.O. Number", _
Title:="Enter P.O. Number", _
Type:=2)

Set rngOrder = ActiveSheet.Range("A:A").Find( _
what:=strReferenceNumber, _
lookat:=xlWhole)

If rngOrder Is Nothing Then
MsgBox "P.O. not found"
Else
ActiveSheet.Unprotect
rngOrder.Offset(0, 1).Select
End If
End Sub


In article <8fc8f484cd4a6@uwe, "bamenell" <u48632@uwe wrote:

I got this code to work and find a record in a range of data and select that
row. But it only finds numbers. I need it to find a string, or a letter-
number combination. What do I need to change?

Private Sub CommandButton6_Click()
ActiveSheet.Unprotect
Dim rngOrder As Range
Dim lngReferenceNumber As Long

lngReferenceNumber = Application.InputBox( _
Prompt:="Enter P.O. Number", _
Title:="Enter P.O. Number", _
Type:=1)

Set rngOrder = Worksheets("PO's").Range("A:A").Find( _
what:=lngReferenceNumber, _
lookat:=xlWhole)

If rngOrder Is Nothing Then
MsgBox "P.O. not found"
ActiveSheet.Protect
Else
With rngOrder
.Activate
Selection.Offset(0, 1).Select


End With
End If


End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Using Input Bx to Find Record

the code should work on a string only if the string in the text box exactly
matches the cell. If the string in the box contains only a portion of the
cell data then make the following change

from:
xlWhole
to:
xLPart

"bamenell" wrote:

I got this code to work and find a record in a range of data and select that
row. But it only finds numbers. I need it to find a string, or a letter-
number combination. What do I need to change?

Private Sub CommandButton6_Click()
ActiveSheet.Unprotect
Dim rngOrder As Range
Dim lngReferenceNumber As Long

lngReferenceNumber = Application.InputBox( _
Prompt:="Enter P.O. Number", _
Title:="Enter P.O. Number", _
Type:=1)

Set rngOrder = Worksheets("PO's").Range("A:A").Find( _
what:=lngReferenceNumber, _
lookat:=xlWhole)

If rngOrder Is Nothing Then
MsgBox "P.O. not found"
ActiveSheet.Protect
Else
With rngOrder
.Activate
Selection.Offset(0, 1).Select


End With
End If


End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Using Input Bx to Find Record

No -

by using Type:=1 in the InputBox method, he was restricting entries to
numbers.

Also by assigning the results to a Long variable, entering letters or an
alphanumeric combination would cause an error - the variable should be a
String variable.


In article ,
Joel wrote:

the code should work on a string only if the string in the text box exactly
matches the cell.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using Input Bx to Find Record

This works just like I needed it to. Thank you very much!
--
Peace,
Brent

JE McGimpsey wrote:
One way:

Private Sub CommandButton6_Click()
Dim rngOrder As Range
Dim strReferenceNumber As String

strReferenceNumber = Application.InputBox( _
Prompt:="Enter P.O. Number", _
Title:="Enter P.O. Number", _
Type:=2)

Set rngOrder = ActiveSheet.Range("A:A").Find( _
what:=strReferenceNumber, _
lookat:=xlWhole)

If rngOrder Is Nothing Then
MsgBox "P.O. not found"
Else
ActiveSheet.Unprotect
rngOrder.Offset(0, 1).Select
End If
End Sub

I got this code to work and find a record in a range of data and select that
row. But it only finds numbers. I need it to find a string, or a letter-

[quoted text clipped - 27 lines]

End Sub


--
--
Peace,
Brent

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
using record macro, can I stop it to get user input? CeeDee Excel Programming 1 December 4th 08 05:27 PM
Data input and database record using macro's Sum Limit and marking Excel Programming 1 January 4th 08 07:45 PM
Obtaining a single Access record from Excel input travis Links and Linking in Excel 5 November 23rd 05 09:02 AM
Find Record Janis in Minnesota Excel Discussion (Misc queries) 0 September 2nd 05 04:54 PM
Finding a record based on user input Soundman Excel Discussion (Misc queries) 5 June 21st 05 03:06 AM


All times are GMT +1. The time now is 08:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"