Forum Discussion
Clint_E_Hill
Oct 04, 2023Brass Contributor
Beginner VBA - Change Selection in Sample Uppercase Routine
How do you modify the sample code to perform the text case on:
- A user-selected cell?
- A user-selected range?
- The entire worksheet?
Sub Uppercase()
' Loop to cycle through each cell in the specified range.
For Each x In Range("A1:A5")
' Change the text in the range to uppercase letters.
x.Value = UCase(x.Value)
Next
End Sub
Thanks,
Clint
Sub Uppercase_selection() Dim rng, x As Range Set rng = Selection ' Loop to cycle through each cell in the specified range. For Each x In rng ' Change the text in the range to uppercase letters. x.Value = UCase(x.Value) Next End SubWith this code you can either select a cell or a range. Then run the code to change the selected cell or range to uppercase. I wouldn't run this code for the entire worksheet (17,178 billion cells) since it would run forever.
2 Replies
- OliverScheurichGold Contributor
Sub Uppercase_selection() Dim rng, x As Range Set rng = Selection ' Loop to cycle through each cell in the specified range. For Each x In rng ' Change the text in the range to uppercase letters. x.Value = UCase(x.Value) Next End SubWith this code you can either select a cell or a range. Then run the code to change the selected cell or range to uppercase. I wouldn't run this code for the entire worksheet (17,178 billion cells) since it would run forever.
- Clint_E_HillBrass ContributorHello Oliver,
Perfect! I thank you sir.
Clint