Convert Case Without Loop

Nanogirl21

Active Member
Joined
Nov 19, 2013
Messages
330
Office Version
  1. 365
Platform
  1. Windows
Is there a code that I can add in my VBA that will convert selected columns to proper case without looping?

columns = m, q, ae, and af.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Code:
Dim rng As Range
Set rng = Intersect([M:M], ActiveSheet.UsedRange)
rng = Evaluate("index(proper(" & rng.Address & "),)")

Note : rng needs to be one area only (i.e. contiguous cells)
 
Last edited:
Upvote 0
The below code is using a loop but it should be pretty quick as I copy to the data to an array then copy back into the sheet …

Code:
Sub ProperCase()

Dim Arr() As Variant, Rg As Range, lRow As Long

For i = 13 To 32
    If i = 13 Or i = 17 Or i = 31 Or i = 32 Then
        lRow = ActiveSheet.Cells(Rows.Count, i).End(xlUp).Row
        Set Rg = ActiveSheet.Range(Cells(1, i), Cells(lRow, i))
            Arr = Rg
                For x = LBound(Arr) To UBound(Arr)
                    Arr(x, 1) = WorksheetFunction.Proper(Arr(x, 1))
                Next x
            Rg = Arr
    End If
Next i
    
End Sub
 
Upvote 0
Code:
Dim rng As Range
Set rng = Intersect([M:M], ActiveSheet.UsedRange)
rng = Evaluate("index(proper(" & rng.Address & "),)")

<g class="gr_ gr_9 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="9" data-gr-id="9">Note :</g> rng needs to be one area only (i.e. contiguous cells)

This worked perfectly and was easy to understand. How would I modify to use other formats (ie: all lower case, all upper case, sentence case). Thank you.
 
Upvote 0
How would I modify to use other formats (ie: all lower case, all upper case, sentence case).

rng = Evaluate("index(lower(" & rng.Address & "),)")


rng = Evaluate("index(upper(" & rng.Address & "),)")
 
Upvote 0
To capitalise first letter only :
Code:
Dim rng$: rng = Intersect([M:M], ActiveSheet.UsedRange).Address
Range(rng) = Evaluate("INDEX(UPPER(LEFT(" & rng & ",1))&LOWER(RIGHT(" & rng & ",LEN(" & rng & ")-1)),)")
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

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