jakeman
Active Member
- Joined
- Apr 29, 2008
- Messages
- 325
- Office Version
- 365
- Platform
- Windows
Hi guys - I'm trying to store a variable in one module that is created by a user input box and retrieve that variable in another module, but it is not working properly. I've verified that my module is global, not specific to a sheet.
The findString variable is not passing for some reason, it keeps showing up as empty when I run Sub FindNextString.
Here is my code:
The findString variable is not passing for some reason, it keeps showing up as empty when I run Sub FindNextString.
Here is my code:
Code:
Option Explicit
Public findString, findString2 As String
Public Sub FindFirstString()
Dim findString, findString2 As String
Dim rng As Range
findString = InputBox("Enter the prefix of the part # you're looking for: AA or BB")
findString2 = findString & "*"
If Trim(findString2) <> "" Then
With Sheets("Parts").Range("A2:G500")
Set rng = .Find(What:=findString2, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
MsgBox "Value has been found in cell: " & ActiveCell.Address
Else
MsgBox "Nothing found"
End If
End With
End If
End Sub
Sub FindNextString()
Dim rng As Range
findString2 = findString & "*"
If findString2 <> "" Then
With Sheets("Parts").Range("A2:G500")
Set rng = .Find(What:=findString2, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
MsgBox "Value has been found in cell: " & ActiveCell.Address
Else
MsgBox "Nothing found"
End If
End With
End If
End Sub