大写less于五个字符的任何单词
如果A列中的字母小于等于4个字母,我怎样才能将缩写字母大写?
我无法在网上find任何具体的缩写词。
UCASE(“string”)将工作。
Sub stringtest() If Len(Range("A1")) < 5 Then Range("A1") = UCase(Range("A1")) End If End Sub
在数组中使用单个镜头(对于A1:A50000 ),使用工作表函数Proper
:
[a1:A50000] = Application.Evaluate("=IF(len(A1:A50000)<5,Proper(A1:a50000),a1:a50000)")
这里是一个循环。 这假设列A中的每个单元格都将有一些内容,直到完成 – 它将停在A列中的第一个空单元格上。
Sub initCaps() Dim intRow As Integer Dim aryWords() As String Dim firstWord As String Dim strNew As String intRow = 1 Do Until Range("A" & intRow) = ""'Look for a blank call in A, then stop. aryWords() = (split(Range("A" & intRow), " "))'Make an array of the cell. firstWord = aryWords(0)'Get the first word. If Len(firstWord) < 5 Then'Test the first word length. firstWord = UCase(firstWord)'Change it to upper case. strNew = firstWord & " "'Add a space to re-build the string If UBound(aryWords()) > 0 Then For I = 1 To UBound(aryWords()) strNew = strNew & aryWords(I) & " "'Put back the rest of the words. Next End If Range("A" & intRow) = strNew'Put it back into the cell, modified. Erase aryWords() firstWord = "" strNew = "" Else Erase aryWords()'Clean up. firstWord = "" strNew = "" End If intRow = intRow + 1 Loop'Do it again! End Sub
祝你好运!