You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

大写转换VBA函数在筛选单元格上运行异常求助

筛选单元格中使用makeUpper函数出现无关数据粘贴问题

我使用以下makeUpper函数已有数周,发现该函数在筛选单元格上运行时,会向目标范围粘贴无关数据。我尝试添加语句Selection.SpecialCells(xlCellTypeVisible).Areas,但并未解决问题,附上函数代码及运行前后的效果图,恳请协助解决该问题。

原函数代码

Sub makeUpper(rng As Range)
    Dim v As Long, w As Long, vUPRs As Variant

    With rng
        If .CountLarge = 1 Then
            ' create array if rng is a single-cell
            ReDim vUPRs(1 To 1, 1 To 1)
            vUPRs(1, 1) = .Value2
        Else
            vUPRs = .Value2
        End If

        For v = LBound(vUPRs, 1) To UBound(vUPRs, 1)
            For w = LBound(vUPRs, 2) To UBound(vUPRs, 2)
                vUPRs(v, w) = UCase(vUPRs(v, w))
            Next
        Next

        .Value2 = vUPRs
    End With
End Sub

尝试添加的语句

Selection.SpecialCells(xlCellTypeVisible).Areas

运行效果

运行前

运行前

运行后

运行后

内容的提问来源于stack exchange,提问作者Spark

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 19:01:10