Query on capital letters

srsteiner

New Member
Joined
Mar 15, 2004
Messages
25
Is it possible to query a field on capital letters only.

For example I have a table whose records look like this:

HR
three
Heat Rate
hr online
Hrate

and I want the query to just return the following records:

HR
Heat Rate

Thank you.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You can use a custom VBA function and call that function from a query to get your results. Basically, you want to return all records where a certain field has a capital letter in it. Capital letters would have an ASCII value between 65 and 90. Here's the function:
Code:
Public Function fIs_UCase(strText As String) As Boolean
Dim i As Long
Dim lenText As Long
lenText = Len(strText)
fIs_UCase = False
For i = 1 To lenText
    If Asc(Mid(strText, i, 1)) >= 65 And Asc(Mid(strText, i, 1)) <= 90 Then
        fIs_UCase = True
        Exit Function
    End If
Next i
End Function

You can now call this function from your query. Pull down the field that you want to see. Next, define a new field by:
Code:
fIs_UCase([Your_Field_Here])
and in the Criteria of this new field, type True. It should be noted that this function would break if you tried to pass in a Null value, so if you have Nulls in your field, you may want to first write a query which eliminates those Nulls and then use this function in a query based off of that query.
 
Upvote 0

Forum statistics

Threads
1,221,680
Messages
6,161,248
Members
451,692
Latest member
jmaskin

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