Home

Macro in Excel

%3CLINGO-SUB%20id%3D%22lingo-sub-720457%22%20slang%3D%22en-US%22%3EMacro%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-720457%22%20slang%3D%22en-US%22%3E%3CP%3EGood%20afternoon%2C%3C%2FP%3E%3CP%3EI%20just%20tried%20to%20write%20my%20first%20macro.%20I%20get%20a%20lot%20of%20spreadsheets%26nbsp%3Bwith%20all%20text%20in%20upper%20case.%20I%20want%20it%20to%20be%20converted%20into%20first%20letter%20upper%20case%20and%20rest%20lower%20case.%20I%20managed%20to%20write%20and%20record%20the%20macro%20(took%20me%20much%20longer%20than%20I%20care%20to%20admit).%20Issue%20is%2C%20it%20always%20applies%20to%20the%20exact%20cell%20I%26nbsp%3Bwrote%20it%20in%20(C2%20in%20my%20case).%20How%20can%20I%20edit%20it%20in%26nbsp%3Ba%20way%20that%20I%20can%20click%20on%20any%20cell%20and%20execute%20that%20macro%20with%20the%20assigned%20short%20cut%3F%3C%2FP%3E%3CP%3EAppreciate%20any%20feedback%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-720457%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-720638%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-720638%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366604%22%20target%3D%22_blank%22%3E%40JoergSchmitt%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%3C%2FP%3E%3CP%3EYou%20recorded%20an%20%22Absolute%20Macro%22%20which%20repeats%20the%20same%20instructions%20to%20the%20same%20selection%20where%20you%20recorded%20it.%3C%2FP%3E%3CP%3EYou%20need%20to%20Re-record%20the%20macro%20as%20a%20%22RELATIVE%22%20macro%20by%20highlighting%20the%20command%20%22USE%20RELATIVE%20REFERENCE%22%20in%20the%20Code%20group%20on%20the%20Left%20side%20of%20the%20Developer%20Tab%20of%20the%20Ribbon.%3C%2FP%3E%3CP%3EThe%20macro%20recorder%20will%20record%20the%20steps%20RELATIVE%20to%20your%20starting%20point%20%26amp%3B%20will%20run%20the%20same%20steps%20Relative%20to%20the%20selected%20cell%20when%20you%20run%20it%20with%20a%20shortcut%20or%20any%20other%20method.%3C%2FP%3E%3CP%3EHope%20that%20helps%3C%2FP%3E%3CP%3ENabil%20Mourad%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-721008%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-721008%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366604%22%20target%3D%22_blank%22%3E%40JoergSchmitt%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20J%C3%B6rg%2C%3C%2FP%3E%3CP%3Etry%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3ESub%20ConvertToUpper()%3CBR%20%2F%3EDim%20rngCell%20As%20Range%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20Each%20rngCell%20In%20Selection%3CBR%20%2F%3ErngCell.Value%20%3D%20UCase(rngcell.value)%3CBR%20%2F%3ENext%20rngCell%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3ESub%20ConvertToLower()%3CBR%20%2F%3EDim%20rngCell%20As%20Range%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20Each%20rngCell%20In%20Selection%3CBR%20%2F%3ErngCell.Value%20%3D%20LCase(rngcell.value)%3CBR%20%2F%3ENext%20rngCell%3CBR%20%2F%3EEnd%20Sub%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%20regards%3C%2FP%3E%3CP%3EBernd%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fvba-tanker.com%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EA%20database%20full%20of%20macros%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-721912%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-721912%22%20slang%3D%22en-US%22%3E%3CP%3EBernd%20good%20morning%2C%3C%2FP%3E%3CP%3EThanks%20for%20the%20quick%20reply.%20I%20will%20let%20you%20know%20whether%20I%20killed%20my%20computer...%3C%2FP%3E%3CP%3EJoerg%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-722091%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-722091%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366604%22%20target%3D%22_blank%22%3E%40JoergSchmitt%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20sounds%20like%26nbsp%3B%20you%20want%20to%20change%20to%20proper%20case.%26nbsp%3B%20Try%20this.%26nbsp%3B%20It%20also%20checks%20for%20any%20cells%20that%20have%20formulas%20(can%20cause%20problems).%26nbsp%3B%20Select%20your%20cells%20%26amp%3B%20run%20the%20macro.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESub%20ProperCase()%3CBR%20%2F%3EDim%20Rng%20As%20Range%3CBR%20%2F%3EFor%20Each%20Rng%20In%20Selection.Cells%3CBR%20%2F%3EIf%20Rng.HasFormula%20%3D%20False%20Then%3CBR%20%2F%3ERng.Value%20%3D%20Application.Proper(Rng.Value)%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3ENext%20Rng%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
JoergSchmitt
New Contributor

Good afternoon,

I just tried to write my first macro. I get a lot of spreadsheets with all text in upper case. I want it to be converted into first letter upper case and rest lower case. I managed to write and record the macro (took me much longer than I care to admit). Issue is, it always applies to the exact cell I wrote it in (C2 in my case). How can I edit it in a way that I can click on any cell and execute that macro with the assigned short cut?

Appreciate any feedback

Thanks

4 Replies

@JoergSchmitt 

Hi

You recorded an "Absolute Macro" which repeats the same instructions to the same selection where you recorded it.

You need to Re-record the macro as a "RELATIVE" macro by highlighting the command "USE RELATIVE REFERENCE" in the Code group on the Left side of the Developer Tab of the Ribbon.

The macro recorder will record the steps RELATIVE to your starting point & will run the same steps Relative to the selected cell when you run it with a shortcut or any other method.

Hope that helps

Nabil Mourad

@JoergSchmitt 

Hi Jörg,

try this:

 

Sub ConvertToUpper()
Dim rngCell As Range

For Each rngCell In Selection
rngCell.Value = UCase(rngcell.value)
Next rngCell
End Sub


Sub ConvertToLower()
Dim rngCell As Range

For Each rngCell In Selection
rngCell.Value = LCase(rngcell.value)
Next rngCell
End Sub

 

Best regards

Bernd

A database full of macros

 

Bernd good morning,

Thanks for the quick reply. I will let you know whether I killed my computer...

Joerg

@JoergSchmitt 

 

It sounds like  you want to change to proper case.  Try this.  It also checks for any cells that have formulas (can cause problems).  Select your cells & run the macro.

 

Sub ProperCase()
Dim Rng As Range
For Each Rng In Selection.Cells
If Rng.HasFormula = False Then
Rng.Value = Application.Proper(Rng.Value)
End If
Next Rng
End Sub

 

 

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
21 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies