I have made several work sheets with clients details on eg, name, address etc. In some of the cells text is all uppercase and in others lower.
How do I create the entire work sheet into capitalization (first letter capital with the rest of text lower) without using PROPER function, where it puts the result in another cell.
Any help would be greatful as I am taking forever to work this one out, I would of thought this would be a simple solution to achieve but Im finding it not.
wideboards![]()
Perhaps:
Option Explicit Sub MakeProper() Dim rngCell As Range Dim lngCalc As Long With Application lngCalc = .Calculation .Calculation = xlManual .ScreenUpdating = False End With For Each rngCell In Cells.SpecialCells(xlCellTypeConstants) rngCell = Evaluate("PROPER(" & rngCell.Address & ")") Next rngCell Set rngCell = Nothing With Application .Calculation = lngCalc .ScreenUpdating = True End With End Sub
Regards
Jon (Excel 2003, XP Pro)
Possibly using Evaluate method ?
Very basic example I'm afraid as I'm heading off for lunch...
EDIT - in essence the above is a reiteration of JvH's post...Public Sub DoItProper() Dim rngData As Range, strRng As String With ActiveSheet Set rngData = .UsedRange strRng = rngData.Address rngData.Value = .Evaluate("=IF(ROW(" & strRng & "),PROPER(" & strRng & "))") Set rngData = Nothing End With End Sub
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Try this code. It will apply the PROPER worksheet function to the range you have selected.
Sub a() Dim rCell As Range For Each rCell In Selection rCell.Value = Application.WorksheetFunction.Proper(rCell.Value) Next End Sub
Please disregard anything in the above post. It may well have been edited without my consent, as has been the case with several posts and threads recently.
I can't take credit for that - I picked it up from Pedro (c/o Bill Jelen's book)... moreover my quick demo makes assumptions of there being no formulae etc... to limit processing as much as possible (and so as to avoid overriding formulae) perhaps:
Public Sub DoItProper() Dim rngData As Range, rngArea As Range, strRng As String With ActiveSheet Set rngData = .UsedRange.SpecialCells(xlCellTypeConstants,xlTextValues) For Each rngArea in rngData.Areas strRng = rngArea.Address rngArea.Value = .Evaluate("=IF(ROW(" & strRng & "),PROPER(" & strRng & "))") Set rngArea = Nothing Next rngArea Set rngData = Nothing End With End Sub
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
The use of SpecialCells(xlCellTypeConstants, xlTextValues) is imperative because:
1. it reduces the size of the range to loop through (which can be avoided using Lukes method)
and
2. because without it, it will convert formula to constants.
Last edited by JONvdHeyden; 06-24-2009 at 08:28 AM.
Regards
Jon (Excel 2003, XP Pro)
Where would I put this code and how? I am very new to this or I have just simply forgot.
Simple instructions please.
Thank you, Ive successfully done it.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks