Hello folks:
I have the following global variable:
I then reference like this:
I would like to call it from my userform, here is my code:
The code runs, but the variable is not storing. The code filters everything out, instead of what I entered in the form. For reference, here is the filterSheets function
I have the following global variable:
Code:
Option Explicit
'Public declarations for the project
Public locationCode As String
I then reference like this:
Code:
Public Property Get locationCode() As String
'Declaration to access the data entered in the
'locationCode from anywhere on the project
locationCode = frmEnterLocation.txtLocationCode.Value
End Property
I would like to call it from my userform, here is my code:
Code:
Private Sub cmdOKButton_Click()
frmEnterLocation.txtLocationCode.SetFocus
If locationCode = "" Then
MsgBox "You have not entered a Location Code", vbCritical, "Please Enter a Location Code"
frmEnterLocation.txtLocationCode.SetFocus
Else
Unload Me
On Error Resume Next
Set ws = wksDenialReport
filterRange = ("G2:G")
compOperator = "<>"
filterString = locationCode
Call filterSheets (ws, filterRange, compOperator, filterString)
The code runs, but the variable is not storing. The code filters everything out, instead of what I entered in the form. For reference, here is the filterSheets function
Code:
Public Function filterSheets(Sheets As Worksheet, searchRange As String, operator As String, filterString As String)
Dim lngLastRow As Long
Application.ScreenUpdating = False
With Sheets
lngLastRow = GETLASTROW(.Cells)
If lngLastRow > 1 Then
'we don't want to delete our header row
With .Range(searchRange & lngLastRow)
.AutoFilter Field:=1, Criteria1:=operator & filterString
.EntireRow.delete
End With
End If
End With
Application.ScreenUpdating = True
End Function