Skip to main content
2 of 2
deleted 72 characters in body; edited tags; edited title
200_success
  • 144.2k
  • 22
  • 188
  • 473

Transforming the case of text using Excel VBA

I created a simple user form for my VBA course.

enter image description here

I then created the following VBA code:

Private Sub btnModify_Click()

Dim modRange As Range
Set modRange = Selection

Dim modString As String
modString = modRange.Value

    If obUpperCase.Value = True Then
    
        modRange.Value = UCase(modString)
        
        btnModify.Value = False
        
    ElseIf obLowerCase.Value = True Then
    
        modRange.Value = LCase(modString)
        
        btnModify.Value = False
        
    ElseIf obProperCase.Value = True Then
    
        modRange.Value = Application.Proper(modString)
        
        btnModify.Value = False
        
    End If

End Sub

Is it possible to split the btnModify_Click into two procedures?

The first procedure would check which OptionButton is clicked and return a "formatting" type.

The second would be the actual btnModify_Click. It would take the active selection and apply the formatting type returned from the first procedure.

My apologies for not posting any code along these lines but I don't have a grasp of how procedures work yet. I have an idea but this seems like a simple enough example to get me started (perhaps too simple?).

On a minor note, I don't like the style of the buttons. They have a classic look, and even though there is a time an place for this specific style, is there any way to obtain "better" looking buttons?

Nahuatl
  • 131
  • 1
  • 9