Excel VBA - Capitalizing all selected cells in column on double click

前端 未结 2 1462
萌比男神i
萌比男神i 2021-01-19 18:42

I have a very simple VBA script, that capitalizes the selected cell:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Acti         


        
2条回答
  •  自闭症患者
    2021-01-19 18:53

    Like I mentioned, Why not a shortcut key?. You can assign a shortcut key for your macro as shown below

    enter image description here

    Now all you have to do is select the column and press the shortcut key.

    Also, instead of looping through every cell in a column, here is a code which is based on a ONE LINER HACK by Peter Albert.

    Put this in a module.

    Sub ChangeToUpper()
        Dim rng As Range
    
        '~~> Check if what the user selected is a valid range
        If TypeName(Selection) <> "Range" Then
            MsgBox "Select a range first."
            Exit Sub
        End If
    
        Set rng = Selection
    
        rng = WorksheetFunction.Transpose(Split(UCase(Join( _
              WorksheetFunction.Transpose(rng), vbBack)), vbBack))
    End Sub
    

    Screenshot:

    enter image description here

提交回复
热议问题