Convert Case Without Loop

Nanogirl21

Active Member
Joined
Nov 19, 2013
Messages
331
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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