need help with minor adjustment to a macro

skyport

Active Member
Joined
Aug 3, 2014
Messages
374
The current macro I am using very nicely caps all words in each cell in a column, which is the main idea. The problem is I am now running into the following issue:

Consider the following sentence in any cell in column A:

claimant's recorded statement

After the macro is ran it would obviously cap each word as follows:


Claimant's Recorded Statement

However, if the original sentence contains something with pre-existing multiple caps consecutively such as the 3 examples below where the issue pertains to MRI and QME and MI :

review of MRI Of thoracic spine
MRI Of thoracic spine
panel QME Ml-104 supplemental report

The current macro I am using would translate those 3 sentences as follows:

Review Of Mri Of Thoracic Spine
Mri Of Thoracic Spine
Panel Qme Mi-104 Supplemental Report

Instead of as it needs to be like the following:

Review Of MRI Of Thoracic Spine
MRI Of Thoracic Spine
Panel QME Ml-104 Supplemental Report

Conclusion: Because such situations only occur with such combos as MRI, QME or MI entered into the cell as caps already before the macro is even used, I was hoping there would be a way for the program to do what it currently does yet skip over any current letter already in caps and not change it OR maybe it could recognize and leave untouched or skip over any situation where a word already exists with a cap or maybe 2 caps or more already in it.

Below is the program I am using:

Sub ConvertSelectionUpper_V4()
' hiker95, 08/27/2014, ME800718
Dim c As Range, s, i As Long, s2, h As String
Application.ScreenUpdating = False
With Selection
.Value = Evaluate("=if(len(" & .Address & "),substitute(proper(" & .Address & "),"" And "","" and ""),"""")")
.Columns.AutoFit
End With
For Each c In Selection
h = ""
If InStr(c, "'") Then
s = Split(Trim(c), " ")
For i = LBound(s) To UBound(s)
If InStr(s(i), "'") Then
s2 = Split(s(i), "'")
h = h & s2(0) & "'" & LCase(s2(1)) & " "
Else
h = h + s(i) & " "
End If
Next i
If Right(h, 1) = " " Then
h = Left(h, Len(h) - 1)
End If
c = h
End If
Next c
Application.ScreenUpdating = True
End Sub

Can anyone help on this one???
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
The following splits by space, capitalizes the first letter and then joins with a space. You'll need to adapt to suit.

Code:
strg = "review of MRI Of thoracic spine"
strgarr = Split(strg, " ")
For j = 0 To UBound(strgarr)
    temp = strgarr(j)
    temp = UCase(Left(temp, 1)) & Mid(temp, 2)
    strgarr(j) = temp
Next
newstrg = Join(strgarr, " ")
 
Upvote 0
I'm afraid I am not able to understand too much on this. Someone here on Excel made the program for me. I am not sure how you are suggesting the addition would be added into it or function on it's own. Also, not sure about the adapting
 
Upvote 0
If that's all you want the macro to do, then replace what you have with this:

Code:
Sub ConvertSelectionUpper_V4()
With Selection
For Each c In Selection
strgarr = Split(c.Value, " ")
For j = 0 To UBound(strgarr)
    temp = strgarr(j)
    temp = UCase(Left(temp, 1)) & Mid(temp, 2)
    strgarr(j) = temp
Next
c.Value = Join(strgarr, " ")
Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,691
Messages
6,126,220
Members
449,303
Latest member
grantrob

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