How to capitalize everything before a certain character?

Burrgogi

Active Member
Joined
Nov 3, 2005
Messages
340
Office Version
  1. 2010
Platform
  1. Windows
In column A, I have some text:
Hello good day.mp3
Hello good day.flac
etc.

I'd like to capitalize everything before the period. I don't need the file extension capitalized.

I have a feeling that I need to combine the PROPER function with the FIND function but I'm struggling to find the right formula. I'm lost. :(
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
This is another option using a UDF which should work considering there's always a space between the words & should work correctly in something like "I'd love you.mp3" without capitalizing the d in I'd … I'm sure Rick will come up with something more robust & crazy one-liner UDF ?

VBA Code:
Function Cap(Txt As String) As String
   For x = 0 To UBound(Split(Txt))
      Cap = Cap & j & UCase(Left(Split(Txt)(x), 1)) & Mid(Split(Txt)(x), 2)
      j = " "
   Next
End Function
 
Upvote 0
Challenges, always challenges :giggle:
VBA Code:
Function Cap(Txt As String) As String
  Cap = Evaluate("SUBSTITUTE(PROPER(SUBSTITUTE(""" & Txt & """,""'"",""zxzx"")),""zxzx"",""'"")")
End Function
Note 1: This will work for any letter or letters following the apostrophe (e.g., it's, I'm, we'd, you'll, etc.)

Note 2: This will not work correctly if you have text encased in apostrophes (e.g., john 'big man' jones).
 
Last edited:
Upvote 0
While the proper function won't be suitable for the OP requirement due to examples like "XI Kyrie Eleison.mp3" but I'm really amazed of how you always come up with alternative solutions such as the apostrophes smartly with the "zxzx" … Always learning from you Rick & thanks for the knowledge sharing :)
 
Upvote 0
@Rick,

Your function results is marked in red
III Some Filename.mp3Iii Some Filename.Mp3
XI Kyrie Eleison.mp3Xi Kyrie Eleison.Mp3
please can you modify to results:

III Some Filename.Mp3
XI Kyrie Eleison.Mp3
 
Upvote 0
Hi Burrgogi,

In many cases an apostrophe will be followed by an "s" so an extra SUBSTITUTE will fix that.

If you haven't noticed by now, these are song/music titles I'm working with so that's not a safe assumption to make.
There is a variety of letters besides the 's'. For example:

I'm
I've
Shouldn't
etc.

These are just a few examples - there are also french songs involved here. Example:
C'etait Ce Soir.mp3
 
Upvote 0
#2. The PROPER function is kind of mucking up the works a bit. It's converting second letter (actually all letters after the 1st one) in these particular scenarios lowercase which is definitely not what I want.
III Some Filename.mp3
XI Kyrie Eleison.mp3

Becomes this:
Iii Some Filename.mp3
Xi Kyrie Eleison.mp3
We are going to need a "rule" from you on how to proceed. I can understand the problem with III, but Xi is a real word (14th letter of the Greek alphabet) so how is the code supposed to distinguish it as not a word in your usage. Is the "rule" to be - if the word contains all upper case letters, leave the word as is? Or, since we do not know what your data actually looks like (maybe always all lower case letters), maybe the "rule" should be if there is any upper case letter anywhere within the word, then leave the word as is? You need to tell us the "rule" that the code should follow.
 
Last edited:
Upvote 0
@Burrgogi, have you tried the function in post #12 ? Does it give any wrong output ? If yes, please show us an example
 
Upvote 0
This sort of thing is notoriously tricky, but here is another udf attempt and some comparisons with earlier udfs.
I note that Rick's udf capitalises the file extension as well. The OP said "I don't need the file extension capitalized" but not "I don't want the file extension capitalized" so I'm not sure if that is an issue and have just highlighted other examples where I think there is or could be a problem with the previous udfs. Most likely examples where mine fails will surface too. :)

VBA Code:
Function CapIt(Txt As String) As String
  Dim RX As Object, itm As Object
  
  Set RX = CreateObject("VBScript.RegExp")
  RX.Global = True
  RX.Pattern = "(^| )([^a-zA-Z]*)([a-z])"
  For Each itm In RX.Execute(Txt)
    Mid(Txt, itm.firstindex + 1, itm.Length) = UCase(Mid(Txt, itm.firstindex + 1, itm.Length))
  Next itm
  CapIt = Txt
End Function

Burrgogi 2020-05-18 1.xlsm
ABCD
1DataPost #12Post #13This Post
2Hello good day.mp3Hello Good Day.mp3Hello Good Day.Mp3Hello Good Day.mp3
3Hello good day.flacHello Good Day.flacHello Good Day.FlacHello Good Day.flac
4He's Funny That Way.mp3He's Funny That Way.mp3He's Funny That Way.Mp3He's Funny That Way.mp3
5III Some Filename.mp3III Some Filename.mp3Iii Some Filename.Mp3III Some Filename.mp3
6XI Kyrie Eleison.mp3XI Kyrie Eleison.mp3Xi Kyrie Eleison.Mp3XI Kyrie Eleison.mp3
7john 'big man' jones.mp3John 'big Man' Jones.mp3John Zxzxbig Man' Jones.Mp3John 'Big Man' Jones.mp3
8(wanna get to know you) that good!.xxx(wanna Get To Know You) That Good!.xxx(Wanna Get To Know You) That Good!.Xxx(Wanna Get To Know You) That Good!.xxx
9#selfie.mp3#selfie.mp3#Selfie.Mp3#Selfie.mp3
10road(s) to rome.abcRoad(s) To Rome.abcRoad(S) To Rome.AbcRoad(s) To Rome.abc
Sheet1
Cell Formulas
RangeFormula
D2:D10D2=CapIt(A2)
 
Upvote 0

Forum statistics

Threads
1,214,878
Messages
6,122,062
Members
449,064
Latest member
scottdog129

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