【问题标题】:Capitalizing all characters Excel VBA大写所有字符Excel VBA
【发布时间】:2015-06-16 19:47:35
【问题描述】:

这应该大写每个字符,但我得到type mismatch 错误。 它适用于具有类似数据的其他工作表,但无缘无故地给我不匹配错误。请帮忙

Private Sub allUpper(ByRef sh As Worksheet)
        Dim arr As Variant, i As Long, j As Long

        If WorksheetFunction.CountA(sh.UsedRange) > 0 Then
            arr = sh.UsedRange  'one interaction with the sheet
            For i = 2 To UBound(arr, 1)         'each "row"
                For j = 1 To UBound(arr, 2)     'each "col"
                    arr(i, j) = UCase(RTrim(Replace(arr(i, j), Chr(10), vbNullString)))
                Next
            Next
            sh.UsedRange = arr  'second interaction with the sheet
        End If
    End Sub

【问题讨论】:

  • 为什么要循环?见THIS

标签: excel ms-access vba capitalization


【解决方案1】:

您的数据中可能存在错误(#N/A 等)。

您可以添加一个检查以防止运行时错误:

If Not IsError(arr(i, j)) Then
    arr(i, j) = UCase(RTrim(Replace(arr(i, j), Chr(10), vbNullString)))
End If

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 2011-01-16
    • 1970-01-01
    • 2017-11-27
    相关资源
    最近更新 更多