ProperCase/UpperCase

nygaaard

New Member
Joined
Oct 8, 2016
Messages
16
Hi!
I have a field in Excel where I write in a customers adress.
I use a code for this so the text in the field will use propercase.
So if I write in "streetname 101" for example, the result will be "Streetname 101".
This works good, but I have a small problem that I wanted to check if it's possible to solve.

If I have a adress with a letter after the streetnumber, for example "Streetname 101B", then propercase will make it "Streetname 101b".
Is it possible somehow to alter the code to always write letters after the streetnumber in uppercase?

This is the code I'm using right now:
Code:
    If Not Application.Intersect(Me.Range("A12:A13"), Target) Is Nothing Then
    If IsNumeric(Target.Value) = False Then
        Application.EnableEvents = False
        'Target.Value = StrConv(Target.Text, vbLowerCase)
        'Target.Value = StrConv(Target.Text, vbUpperCase)
        Target.Value = StrConv(Target.Text, vbProperCase)
        Application.EnableEvents = True
    End If
    End If
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
See if this works..

Code:
If Not Application.Intersect(Me.Range("A12:A13"), Target) Is Nothing Then
    myCount = Len(Target.Value) - Len(Replace(Target.Value, " ", ""))
    If myCount > 0 Then
        arr = Split(Target.Value, " ")
        For i = LBound(arr) To UBound(arr)
            If Not IsNumeric(Left(arr(i), 1)) Then
                arr(i) = StrConv(arr(i), vbProperCase)
            End If
        Next
        Target.Value = Join(arr, " ")
    Else
       Target.Value = StrConv(Target.Value, vbProperCase)
    End If
End If
 
Upvote 0
See if this works..

Code:
If Not Application.Intersect(Me.Range("A12:A13"), Target) Is Nothing Then
    myCount = Len(Target.Value) - Len(Replace(Target.Value, " ", ""))
    If myCount > 0 Then
        arr = Split(Target.Value, " ")
        For i = LBound(arr) To UBound(arr)
            If Not IsNumeric(Left(arr(i), 1)) Then
                arr(i) = StrConv(arr(i), vbProperCase)
            End If
        Next
        Target.Value = Join(arr, " ")
    Else
       Target.Value = StrConv(Target.Value, vbProperCase)
    End If
End If

Hi!
I get a runtime-error "1004" and the whole Excel-file freezes and behaves weird. :eek:
"The method 'Replace' in the object 'Range' failed."
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

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