Forum Discussion

Clint_E_Hill's avatar
Clint_E_Hill
Brass Contributor
Oct 04, 2023
Solved

Beginner VBA - Change Selection in Sample Uppercase Routine

How do you modify the sample code to perform the text case on:

  1. A user-selected cell?
  2. A user-selected range?
  3. 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

  • Clint_E_Hill 

    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 Sub

    With 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

  • Clint_E_Hill 

    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 Sub

    With 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.

Resources