I am trying to filter my movie list. Unfortunately it doesn't work out so well yet. I found a very fast way, but this one is missing a few options.
If I read the entire column into an array and search for the individual words, it takes a relatively long time for over 2000 movies.
What I miss:
In column A I can only filter by the first word. So it only goes from the beginning of the title. For example, "F" finds all "Film*" titles.
In column B and C I would like to be able to sort "from to". So all movies after 2012 and for example all with a rating better than 7.
In column G and H I have again the problem that I can only sort from the front. So if the genre Action is in second place, I can't find it. Additional i want to find 2 genres for example:"* Crime * Action*"
What works well is that I can now already combine.
The Excel Sheet:
https://mega.nz/file/RsUXRKgD#4ba95fkQOYiteWCH8WST8AuSKZi0k6YCtkuJkOK8tQc
My Code:
'filter in row2
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LR As Long
If Not Application.Intersect(Range("A2:G2"), Range(Target.Address)) Is Nothing Then
If Cells(2, 1).Value = "" And Cells(2, 2).Value = "" And Cells(2, 3).Value = "" And Cells(2, 4).Value = "" And Cells(2, 5).Value = "" And Cells(2, 6).Value = "" And Cells(2, 7).Value = "" Then
On Error Resume Next
ActiveSheet.ShowAllData
ActiveSheet.Rows.Hidden = False
Else
LR = UsedRange.Rows.Count 'includes hidden rows
Range("A1:G" & LR).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("A1:G3")
End If
End If
End Sub
Private Sub ToggleButton1_Click()
Dim Reihe As String
Reihe = "A"
If ToggleButton1.Value = False Then
Call orderXA(Reihe)
Else
Call orderXD(Reihe)
End If
End Sub
Private Sub ToggleButton2_Click()
Dim Reihe As String
Reihe = "B"
If ToggleButton2.Value = False Then
Call orderXA(Reihe)
Else
Call orderXD(Reihe)
End If
End Sub
Private Sub ToggleButton3_Click()
Dim Reihe As String
Reihe = "C"
If ToggleButton3.Value = False Then
Call orderXA(Reihe)
Else
Call orderXD(Reihe)
End If
End Sub
Private Sub ToggleButton4_Click()
Dim Reihe As String
Reihe = "D"
If ToggleButton4.Value = False Then
Call orderXA(Reihe)
Else
Call orderXD(Reihe)
End If
End Sub
Private Sub ToggleButton5_Click()
Dim Reihe As String
Reihe = "E"
If ToggleButton5.Value = False Then
Call orderXA(Reihe)
Else
Call orderXD(Reihe)
End If
End Sub
Private Sub ToggleButton6_Click()
Dim Reihe As String
Reihe = "F"
If ToggleButton6.Value = False Then
Call orderXA(Reihe)
Else
Call orderXD(Reihe)
End If
End Sub
Private Sub ToggleButton7_Click()
Dim Reihe As String
Reihe = "G"
If ToggleButton7.Value = False Then
Call orderXA(Reihe)
Else
Call orderXD(Reihe)
End If
End Sub
Sub orderXA(Reihe As String)
LR = UsedRange.Rows.Count 'zählt uf versteckte mit
Range("A3:H" & LR).Sort Key1:=Range(Reihe & "4"), order1:=xlAscending, Header:=xlYes
End Sub
Sub orderXD(Reihe As String)
LR = UsedRange.Rows.Count 'zählt uf versteckte mit
Range("A3:H" & LR).Sort Key1:=Range(Reihe & "4"), order1:=xlDescending, Header:=xlYes
End Sub
Why so complicated? Just put on Autofilter. You don't even need VBA for that.
Sorry for the german screenshot.
Related
I am completely new in this and got stuck on something that sounds like a simple thing.
I created simple user form, where assemblers will enter one of the items as a search criteria. The listbox is then populated with all results from original spreadsheet showing the location of that part. Assembler will then select one item that they need to pick and click the button "pick".
What that will do is enter the date in "PickDate" in spreadsheet. And that is where I am stuck.
My thinking was to select the row in the spreadsheet identical to the selected row in listbox, and then create address of the cell using that row and column. But it doesn't work. Tried several things that I could find on internet and nothing works. At one point I had date being entered in correct column, but not correct row. Unfortunately, cannot remember what that code was.
Any help would be appreciated.
Thanks a lot. userform spreadsheet
Private Sub PickBtn_Click()
Dim i As Integer
For i = 1 To Range("A10000").End(xlUp).Row
If Cells(i, 2) = Results.List(Results.ListIndex) Then
Rows(i).Select
.Range(Selection, 7).Value = Date
End If
Next i
End Sub
Entry form
Private Sub CancelJob_Click()
'Close EntryForm form
Unload EntryForm
'Show InitialForm form
InitialForm.Show
End Sub
Private Sub UserForm_Initialize()
'Empty all fields
JobBox.Value = ""
Customer.Value = ""
Location.Value = ""
Rack.Value = ""
'Fill combo box with product types
With ProductCombo
.AddItem "Channel Letter Faces"
.AddItem "Channel Letter Backers"
.AddItem "Routed Aluminum Panels"
.AddItem "Routed ACM Panels"
End With
'Set focus on Work order TextBox
JobBox.SetFocus
End Sub
Private Sub SubmitJob_Click()
'Make fields mandatory
If JobBox.Value = "" Or ProductCombo.Value = "" Or Rack.Value = "" Then
If MsgBox("Cannot submit. Please fill the mandatory fields.",
vbQuestion + vbOKOnly) <> vbOKOnly Then
Exit Sub
End If
End If
'Start transfering process
Dim emptyRow As Long
'Make Sheet1 active
Sheet1.Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information to the table
Cells(emptyRow, 1).Value = Date 'Auto populate 1st column with submission date
Cells(emptyRow, 2).Value = JobBox.Value
Cells(emptyRow, 3).Value = Customer.Value
Cells(emptyRow, 4).Value = Location.Value
Cells(emptyRow, 5).Value = ProductCombo.Value
Cells(emptyRow, 6).Value = Rack.Value
'Save workbook after transfer of data
ActiveWorkbook.Save
'Close EntryForm
Unload Me
'Quit application so that others can use it
'Application.Quit
End Sub
This is complete code for this search part of the userform that I cannot
figure out (I was playing with the code for "submit" button that I am stuck). Maybe it will help for troubleshooting:
Private Sub ClearForm(Except As String)
' Clears the list box and text boxes EXCEPT the text box
' currently having data entered into it
Select Case Except
Case "Job"
FormEvents = False
Customer.Value = ""
Location.Value = ""
Results.Clear
FormEvents = True
Case "Customer"
FormEvents = False
Job.Value = ""
Location.Value = ""
Results.Clear
FormEvents = True
Case "Location"
FormEvents = False
Job.Value = ""
Customer.Value = ""
Results.Clear
FormEvents = True
Case Else
FormEvents = False
Job.Value = ""
Customer.Value = ""
Location.Value = ""
Results.Clear
FormEvents = True
End Select
End Sub
Private Sub ClearBtn_Click()
ClearForm ("")
End Sub
Private Sub Job_Change()
If FormEvents Then ClearForm ("Job")
End Sub
Private Sub Customer_Change()
If FormEvents Then ClearForm ("Customer")
End Sub
Private Sub Location_Change()
If FormEvents Then ClearForm ("Location")
End Sub
Private Sub PickBtn_Click()
Dim i As Integer
Sheet1.Activate
For i = 1 To Range("A10000").End(xlUp).row
If Cells(i, 2) = Results.List(Results.ListIndex) Then
Rows(i).Select
Me.Range("Selection:G").Value = Date
End If
Next i
End Sub
Private Sub SearchBtn_Click()
Dim SearchTerm As String
Dim SearchColumn As String
Dim RecordRange As Range
Dim FirstAddress As String
Dim FirstCell As Range
Dim RowCount As Integer
' Display an error if no search term is entered
If Job.Value = "" And Customer.Value = "" And Location.Value = "" Then
MsgBox "No search term specified", vbCritical + vbOKOnly
Exit Sub
End If
' Work out what is being searched for
If Job.Value <> "" Then
SearchTerm = Job.Value
SearchColumn = "Job"
End If
If Customer.Value <> "" Then
SearchTerm = Customer.Value
SearchColumn = "Customer"
End If
If Location.Value <> "" Then
SearchTerm = Location.Value
SearchColumn = "Location"
End If
Results.Clear
' Only search in the relevant table column i.e. if somone is
searching Location
' only search in the Location column
With Range("Table1[" & SearchColumn & "]")
' Find the first match
Set RecordRange = .Find(SearchTerm, LookIn:=xlValues)
' If a match has been found
If Not RecordRange Is Nothing Then
FirstAddress = RecordRange.Address
RowCount = 0
Do
' Set the first cell in the row of the matching value
Set FirstCell = Range("B" & RecordRange.row)
' Add matching record to List Box
Results.AddItem
Results.List(RowCount, 0) = FirstCell(1, 1)
Results.List(RowCount, 1) = FirstCell(1, 2)
Results.List(RowCount, 2) = FirstCell(1, 3)
Results.List(RowCount, 3) = FirstCell(1, 4)
Results.List(RowCount, 4) = FirstCell(1, 5)
Results.List(RowCount, 5) = FirstCell(1, 7)
RowCount = RowCount + 1
' Look for next match
Set RecordRange = .FindNext(RecordRange)
' When no further matches are found, exit the sub
If RecordRange Is Nothing Then
Exit Sub
End If
' Keep looking while unique matches are found
Loop While RecordRange.Address <> FirstAddress
Else
' If you get here, no matches were found
Results.AddItem
Results.List(RowCount, 0) = "Nothing Found"
End If
End With
End Sub
Private Sub UserForm_Initialize()
FormEvents = True
End Sub
Add another column in the list box to hold the row number.
Results.List(RowCount, 6) = FirstCell.Row
And then code becomes
Private Sub PickBtn_Click()
Dim r as long
r = Results.List(Results.ListIndex,6)
Range(r, 7).Value = Date
End Sub
Hi I have a search form which shows a listbox of results. It starts out empty and when I conduct a search then rows are created but no data is visible. I have checked a few obvious things like color and all seem normal black font etc. If I have the worksheet with the sourcedata in view the data in the list is visible, but in everyday practice that would not be the case. I think it is conducting the search on the correct results but then displaying the equivalent rows from another worksheet. I'm just not sure how to edit the code to avoid this.
My userform code is this, I assume the problem is where it is calling the Results range but I have tried adding a worksheet reference of the source data to the start of Range.Records and that doesn't seem to help:
Option Explicit
' Display All Matches from Search in Userform ListBox
'
Dim FormEvents As Boolean
Private Sub ClearForm(Except As String)
' Clears the list box and text boxes EXCEPT the text box
' currently having data entered into it
Select Case Except
Case "srchStCat"
FormEvents = False
srchStID.Value = ""
srchStSurname.Value = ""
Results.Clear
FormEvents = True
Case "srchStID"
FormEvents = False
srchStCat.Value = ""
srchStSurname.Value = ""
Results.Clear
FormEvents = True
Case "srchStSurname"
FormEvents = False
srchStID.Value = ""
srchStCat.Value = ""
Results.Clear
FormEvents = True
Case Else
FormEvents = False
srchStCat.Value = ""
srchStID.Value = ""
srchStSurname.Value = ""
Results.Clear
FormEvents = True
End Select
End Sub
Private Sub CmdClear_Click()
ClearForm ("")
End Sub
Private Sub CmdClose_Click()
Me.Hide
End Sub
Private Sub srchStCat_Change()
If FormEvents Then ClearForm ("srchStCat")
End Sub
Private Sub srchStID_Change()
If FormEvents Then ClearForm ("srchStID")
End Sub
Private Sub srchStSurname_Change()
If FormEvents Then ClearForm ("srchStSurname")
End Sub
Private Sub CmdSearch_Click()
Dim SearchTerm As String
Dim SearchColumn As String
Dim RecordRange As Range
Dim FirstAddress As String
Dim FirstCell As Range
Dim RowCount As Integer
' Display an error if no search term is entered
If srchStCat.Value = "" And srchStID.Value = "" And srchStSurname.Value = "" Then
MsgBox "No search term specified", vbCritical + vbOKOnly
Exit Sub
End If
' Work out what is being searched for
If srchStCat.Value <> "" Then
SearchTerm = srchStCat.Value
SearchColumn = "Current Role"
End If
If srchStID.Value <> "" Then
SearchTerm = srchStID.Value
SearchColumn = "ID Token"
End If
If srchStSurname.Value <> "" Then
SearchTerm = srchStSurname.Value
SearchColumn = "Surname"
End If
Results.Clear
' Only search in the relevant table column i.e. if somone is searching srchStSurname
' only search in the srchStSurname column
With Worksheets("Staff").Range("StaffFullData[" & SearchColumn & "]")
' Find the first match
Set RecordRange = .Find(SearchTerm, LookIn:=xlValues)
' If a match has been found
If Not RecordRange Is Nothing Then
FirstAddress = RecordRange.Address
RowCount = 0
Do
' Set the first cell in the row of the matching value
Set FirstCell = Range("A" & RecordRange.Row)
' Add matching record to List Box
Results.AddItem
Results.List(RowCount, 0) = FirstCell(1, 2)
Results.List(RowCount, 1) = FirstCell(1, 7)
Results.List(RowCount, 2) = FirstCell(1, 5)
Results.List(RowCount, 3) = FirstCell(1, 18)
RowCount = RowCount + 1
' Look for next match
Set RecordRange = .FindNext(RecordRange)
' When no further matches are found, exit the sub
If RecordRange Is Nothing Then
Exit Sub
End If
' Keep looking while unique matches are found
Loop While RecordRange.Address <> FirstAddress
Else
' If you get here, no matches were found
Results.AddItem
Results.List(RowCount, 0) = "Nothing Found"
End If
End With
End Sub
Private Sub UserForm_Initialize()
FormEvents = True
End Sub
Private Sub Results_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Long
With Me.Results
For i = 0 To .ListCount - 1
If .Selected(i) Then
Me.TextBoxGetStaffFName.Value = .List(i, 1)
Me.TextBoxGetStaffSurname.Value = .List(i, 2)
Me.TextBoxGetStaffID.Value = .List(i, 0)
Exit For
End If
Next
End With
End Sub
Ok just figured out I need to specify the sheet in two places not just one. I needed to edit this section where asterixed
*With Sheet11.Range("StaffFullData[" & SearchColumn & "]")*
' Find the first match
Set RecordRange = .Find(SearchTerm, LookIn:=xlValues)
' If a match has been found
If Not RecordRange Is Nothing Then
*FirstAddress = Sheet11.RecordRange.Address*
Got the solution:
Use
Range.Address(,,,1) to get the full address
I have a macro code but it runs on specific column and on range of 500 only. I wish it should dynamically select column of header 'PRODUCTS' is present. if possible can we increase the limit of 500 to all the data present in column 'PRODUCTS'.
Sub Pats()
myCheck = MsgBox("Do you have Patent Numbers in Column - B ?", vbYesNo)
If myCheck = vbNo Then Exit Sub
endrw = Range("B500").End(xlUp).Row
Application.ScreenUpdating = False
For i = 2 To endrw
PatNum = Cells(i, 2).Value
If Left(Cells(i, 2), 2) = "US" Then
link = "http://www.google.com/patents/" & PatNum
Cells(i, 2).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="http://www.google.com/patents/" & PatNum, ScreenTip:="Click to View", TextToDisplay:=PatNum
With Selection.Font
.Name = "Arial"
.Size = 10
End With
ElseIf Left(Cells(i, 2), 2) = "EP" Then
link = "http://www.google.com/patents/" & PatNum
Cells(i, 2).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="http://www.google.com/patents/" & PatNum, ScreenTip:="Click to View", TextToDisplay:=PatNum
With Selection.Font
.Name = "Arial"
.Size = 10
End With
End If
Next i
End Sub
I would first extract the link building part into a separate subroutine ...
Sub AddLink(c As Range)
Dim link As String
Dim patNum As String
Dim test As String
patNum = c.Value
test = UCase(Left(patNum, 2))
If test = "US" Or test = "EP" Then
link = "http://www.google.com/patents/" & patNum
Else
link = "http://www.www.hyperlink.com/" & patNum
End If
c.Hyperlinks.Add Anchor:=c, Address:=link, ScreenTip:="Click to View", TextToDisplay:=patNum
With c.Font
.Name = "Arial"
.Size = 10
End With
End Sub
Then I would add a function to find the column...
Function FindColumn(searchFor As String) As Integer
Dim i As Integer
'Search row 1 for searchFor
FindColumn = 0
For i = 1 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
If ActiveSheet.Cells(1, i).Value = searchFor Then
FindColumn = i
Exit For
End If
Next i
End Function
Finally I would put it all together ...
Sub Pats()
Dim col As Integer
Dim i As Integer
col = FindColumn("PRODUCTS")
If col = 0 Then Exit Sub
For i = 2 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
AddLink ActiveSheet.Cells(i, col)
Next i
End Sub
I'll admit I have to use SO to remind myself how to get the last used cell on a worksheet (see Find Last cell from Range VBA).
The code below will find which column has the header PRODUCTS and then find the last row in that column and store it in variable lrProdCol.
Sub FindProductLR()
Dim col As Range
Dim endrw As Long
Set col = Rows(1).Find("PRODUCTS")
If Not col Is Nothing Then
endrw = Cells(Rows.count, col.Column).End(xlUp).Row
Else
MsgBox "The 'PRODUCTS' Column was not found in row 1"
End If
End Sub
So replace the following bit of code
myCheck = MsgBox("Do you have Patent Numbers in Column - B ?", vbYesNo)
If myCheck = vbNo Then Exit Sub
endrw = Range("B500").End(xlUp).Row
With the lines above. Hope that helps
I currently use this code to search for a specific value entered by the user. However, I'd like it to test for the value if it's located within the string, for example, if the user typed "Jon" the search results could be "Jon, Jonathan, Jones" etc. I'm thinking I need to utilize the InStr function somehow, but I'm not sure how to set it up... Any help would be appreciated.
Private Sub CommandButton1_Click()
ActiveSheet.Range("H1").Select
Dim MyValue As String
MyValue = TextBox1.Value
If MyValue = "" Then
MsgBox "Please enter a sales managers name!"
TextBox1.SetFocus
Else
Application.EnableEvents = False
Worksheets("Sheet2").Activate
Range("A3:I200").Select
Selection.ClearContents
Worksheets("Sheet1").Activate
Me.Hide
Set i = Sheets("Sheet1")
Set E = Sheets("Sheet2")
Dim d
Dim j
d = 2
j = 2
Do Until IsEmpty(i.Range("A" & j))
If i.Range("A" & j) = MyValue Then
d = d + 1
E.Rows(d).Value = i.Rows(j).Value
End If
j = j + 1
Loop
Application.EnableEvents = True
Worksheets("Sheet2").Activate
ActiveSheet.Range("H1").Select
If Range("A3").Value = "" Then
MsgBox "No results were found."
Else
MsgBox "Results were found!"
End If
End If
Unload Me
End Sub
I'd use AutoFilter(), and make some little refactoring as follows:
Private Sub CommandButton1_Click()
Dim MyValue As String
MyValue = Me.TextBox1.Value
If MyValue = "" Then
MsgBox "Please enter a sales managers name!"
Me.TextBox1.SetFocus
Else
With Worksheets("Sheet1")
With .Range("A1", .Cells(.Rows.count, 1).End(xlUp))
.AutoFilter field:=1, Criteria1:=MyValue & "*"
If Application.WorksheetFunction.Subtotal(103, .Cells) > 1 Then
Worksheets("Sheet2").UsedRange.ClearContents
Intersect(.Parent.UsedRange, .Resize(.Rows.count - 1).Offset(1).SpecialCells(xlCellTypeVisible).EntireRow).Copy Worksheets("Sheet2").Range("A3")
MsgBox "Results were found."
Else
MsgBox "No results were found."
End If
End With
.AutoFilterMode = False
End With
Me.Hide '<--| hide the userform and move 'Unload UserformName' command to the sub that's calling the Userform
End If
End Sub
You can do this pretty easily with a regular expression in the form of something like:
(^Jon\s)|(\sJon\s)|(\sJon$)
I'd wrap it in a function to allow building the pattern dynamically from user input. This is just an example - you'd either need to do some more escaping beyond just the . or (probably better) add input restrictions on the TextBox.
'Add reference to Microsoft VBScript Regular Expressions
Private Function ContainsWord(target As String, search As String) As Boolean
Const template As String = "(^<word>\s)|(\s<word>\s)|(\s<word>$)"
Dim expression As String
expression = Replace$(template, "<word>", Replace$(search, ".", "\."))
With New RegExp
.Pattern = expression
ContainsWord = .Test(target)
End With
End Function
Sample usage:
Public Sub Example()
Debug.Print ContainsWord("foo bar baz", "bar") 'True
Debug.Print ContainsWord("foo barbaz", "bar") 'False
Debug.Print ContainsWord("foobar baz", "bar") 'False
Debug.Print ContainsWord("bar foo baz", "bar") 'True
Debug.Print ContainsWord("foo baz bar", "bar") 'True
End Sub
In your code, you'd just replace the line...
If i.Range("A" & j) = MyValue Then
...with:
If ContainsWord(i.Range("A" & j).Value, MyValue) Then
Note that since you are calling it in a loop, you'd probably want to cache the RegExp in your case though to avoid repeatedly creating it if you have a ton of cells to check.
First off thank you very much. Over the last few months (i believe) my coding has progressed drastically. Any and all criticize is always welcome (rip me apart).
Recently I started to try to use different Subs (I dont quite understand when to use functions etc, but i figure it is good structure practice for when i figure it out.
I am hitting a Run-time 424 Error with the following bit of code in Sub ownerCHECK
Sub OccupationNORMALIZATION()
Dim infoBX As String
' initialize variables
LRow = ActiveSheet.UsedRange.Rows.Count
LCol = ActiveSheet.UsedRange.Columns.Count
STATUScounter = LRow
Do While infoBX = ""
infoBX = InputBox("Enter Occupation Column", "Occupation Column")
Loop
restaurCHECK (infoBX)
Application.ScreenUpdating = True
Application.StatusBar = ""
End Sub
-
Sub restaurCHECK(infoBX As String)
Dim RestaurantS(), RestaurantDQs() As Variant
Dim i, LRow, LCol, STATUScounter As Long
Dim rRng As Range
LRow = ActiveSheet.UsedRange.Rows.Count
LCol = ActiveSheet.UsedRange.Columns.Count
STATUScounter = LRow
RestaurantS = Array("estaur", "food", "cafe", "beverage", "waiter", "waitr", _
"waitstaff", "wait staff", "grill") 'array list of target occupations
RestaurantDQs = Array("fast", "pub", "import", "packing", "processing", "packag", _
"retired", "anufact", "distrib") ' disqualifying words for Restaurante category
Set rRng = Range(infoBX & "2:" & infoBX & LRow)
Application.ScreenUpdating = False
For Each cell In rRng
ownerCHECK (cell)
For i = LBound(RestaurantS) To UBound(RestaurantS)
If InStrRev(cell.Value, UCase(RestaurantS(i))) > 0 Then
cell.Offset(, 1) = "Restaurants"
cell.Interior.Color = 52479
End If
Debug.Print cell.Value
Next
For i = LBound(RestaurantDQs) To UBound(RestaurantDQs)
If InStrRev(cell.Value, UCase(RestaurantDQs(i))) And cell.Interior.Color = 52479 Then
cell.Interior.Color = 255
cell.Offset(, 1) = ""
End If
Next
STATUScounter = STATUScounter - 1
Application.StatusBar = "REMAINING ROWS " & STATUScounter & " tristram "
Next cell
End Sub
-
Sub ownerCHECK(str_owner As Range)
Dim owner() As Variant
owner() = Array("owner", "shareholder", "owns ")
For i = LBound(owner) To UBound(owner)
If InStrRev(str_owner, UCase(owner(i))) > 0 Then
cell.Offset(, 2) = "Owner"
End If
Next
End Sub
I can see a couple of issues in ownerCHECK():
"cell" is not defined (unless it's global)
you shouldn't use "cell" as a variable name (internal VBA property)
check validity of incoming range
.
Option Explicit
Sub ownerCHECK(ByRef rngOwner As Range)
If Not rngOwner Is Nothing Then
Dim owner() As Variant
owner() = Array("OWNER", "SHAREHOLDER", "OWNS ")
For i = LBound(owner) To UBound(owner)
If InStrRev(UCase(rngOwner), owner(i)) > 0 Then
rngOwner.Offset(, 2) = "Owner"
End If
Next
End If
End Sub