How can I fix this function to search all capitalised words in a string against a named range?

Magnatolia

Board Regular
Joined
Jan 19, 2012
Messages
81
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am trying to build a function that I can use to search a selected cell's string and check each capital word (e.g. ART, RESULT) and check against an approved abbreviation list. It will then return the result of disallowed capitalised words in the output. This is the first stage. I then want to include an exclusion of certain capitalised words such as CONTRACTS and CPO.

Code:
Function find_cap_words(Rng As Range)

Dim allowed_abb As Integer
Dim disallowed_abb As Integer
Dim txt
Dim desc() As String
Dim found As Boolean: found = False


desc = Split(Rng.Value, , " ")


For Each txt In desc
MsgBox txt
If (UCase(txt) = txt) Then


    If Range("Abbreviations").Find(txt, , Excel.xlValues) Is Nothing Then
        disallowed_abb = disallowed_abb + 1
        found = False
        Else
        allowed_abb = allowed_abb + 1
        found = True
        
    End If
    End If
    Next


    ActiveCell.Value = "Err: There is/are " & disallowed_abb & " unapproved capitalised words. Review required"
    
        
End Function

I'm getting a value error. I get the correct result through the sub macro.

Any assistance is appreciated.

Thanks!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi,
xlvalues is a Contstant and has value of -4163

Try changing code as follows

Code:
If Range("Abbreviations").Find(txt, , xlValues) Is Nothing Then


also, as you are passing the range as an argument you should be able to use the declared rng parameter & not need to repeat the range in your function

Code:
If Rng.Find(txt, , Excel.xlValues) Is Nothing Then

Dave
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top