【问题标题】:Proper Case up to first instance of ","正确案例,直到“,”的第一个实例
【发布时间】:2014-02-24 02:46:36
【问题描述】:

对此完全感到困惑,我想将列中的名称转换为正确的大小写,但我不想更改标题。

如何转换为正确的大小写直到第一个,

BOB FEGESON
Sally Ran, Ph.D.
GREG HYMAN, MA, CPCC

我明白了

Bob Fegeson
Sally Ran, Ph.d.
Greg Hyman, Ma, Cpcc

想要

Bob Fegeson
Sally Ran, Ph.D.
Greg Hyman, MA, CPCC

谢谢

如果If InStr(cell.Formula, ",") > 0,这将转换为正确的大小写

Sub FindChr()
Dim rAcells As Range
Dim rLoopCells As Range
Dim lReply As Long
Dim myRange As Range
Dim cell As Range

'Set variable to needed cells
Set rAcells = Range("D2", Range("D" & Rows.Count).End(xlUp))
Set rAcells = rAcells.SpecialCells(xlCellTypeConstants, xlTextValues)

Set myRange = Range("D2", Range("D" & Rows.Count).End(xlUp))

For Each cell In myRange
    If InStr(cell.Formula, ",") > 0 Then

    "Cant Not Figure out what goes here"

    Else
        ' Convert to Proper Case
      For Each rLoopCells In rAcells
          rLoopCells = StrConv(rLoopCells, vbProperCase)
      Next rLoopCells
    End If
  Next cell
End Sub

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    试试这个

    Sub FindChr()
        Dim ws As Worksheet
        Dim myRange As Range, cell As Range
        Dim tmpString As String
        Dim MyString As Variant
        Dim i As Long
    
        '~~> Change this to the relevant worksheet
        Set ws = ThisWorkbook.Sheets("Sheet1")
    
        With ws
            Set myRange = .Range("D2", .Range("D" & .Rows.Count).End(xlUp))
    
            For Each cell In myRange
                If InStr(1, cell.Formula, ",") Then
                    MyString = Split(cell.Formula, ",")
    
                    tmpString = StrConv(MyString(0), vbProperCase)
    
                    For i = 1 To UBound(MyString)
                        tmpString = tmpString & "," & MyString(i)
                    Next i
    
                    cell.Formula = tmpString
                Else
                    cell.Formula = StrConv(cell.Formula, vbProperCase)
                End If
            Next cell
        End With
    End Sub
    

    【讨论】:

    • 我注意到我也得到了 Betty H.whitney 和 Hank O'day,而我应该有 Betty H.Whitney 和 Hank O'Day`。谢谢——
    • 我看到您已将此标记为答案。这是否意味着您已经成功实现了上述评论中提到的目标?如果没有,那么试试这个。获得MyString(0) 后,只需检查'.,然后再次拆分,并在将它们更改为正确大小写后将它们连接起来。
    • 不,抱歉,我不太清楚,尽管您在我写的时候回答了这个问题(谢谢)。我会尝试你的建议。
    • Siddharth 用cell.Formula = Application.WorksheetFunction.Proper(cell.Formula) 代替了cell.Formula = StrConv(cell.Formula, vbProperCase)。再次感谢您的宏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-06
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    • 2016-10-09
    • 2018-06-09
    相关资源
    最近更新 更多