2016-07-15 41 views
0

我在以下线程中使用Siddharth Rout的代码来大写所选列的大写,但当我在具有单元格的列上使用它时遇到错误'13'MISMATCH公式在一些范围内。Excel VBA - 利用公式在列中大写所有选定的单元格

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

下面是基于非公式列数据的工作从上面的链接代码:

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 

我搜索了论坛,并没有发现与此相关的细节。所以我GOOGLE了它,并且Mr.Excel有这样的代码,但仍然给出错误'13',当我清除错误信息时,所有内容都被大写。有没有办法消除这个错误?

下面是从Mr.Excel的代码:

Sub MyUpperCase() 

    Application.ScreenUpdating = False 

    Dim cell As Range 
    For Each cell In Range("$A$1:" & Range("$A$1").SpecialCells(xlLastCell).Address) 
     If Len(cell) > 0 Then cell = UCase(cell) 
    Next cell 

    Application.ScreenUpdating = True 

End Sub 
+0

你需要配方吗?这听起来像添加一行代码将公式转换为值是最简单的解决方案? – StevenWalker

+0

我会将此视为一种可能的修复方法,谢谢。 –

+0

访问使用的范围,将其全部复制,然后粘贴特殊值。我记不清头顶上的确切语法,并且在移动设备上,但您可以很容易地找到示例Google搜索。已发布的其他解决方案更可取,但可以保留公式 – StevenWalker

回答

1

检查如果细胞具有式和或错误,如果是,则忽略。

Sub MyUpperCase() 

    Application.ScreenUpdating = False 

    Dim cell As Range 
    For Each cell In Range("$A$1:" & Range("$A$1").SpecialCells(xlLastCell).Address) 

     '/ Exclude errors 
     If Not IsError(cell) Then 
     If Len(cell) > 0 And Not cell.HasFormula Then 
      cell = UCase(cell) 
     End If 
    End If 
    Next cell 

    Application.ScreenUpdating = True 
End Sub 
+0

此更改仍导致错误“13”。再次清除错误,整张纸被大写。它似乎只在具有这种情况的公式表上发生。感谢您的帮助,我将不得不寻找解决办法。 –

+0

你的牢房有错误吗?如果是,则检查它们并使用“IsError”进行排除。我已经更新了答案。 – cyboashu

+0

不,没有错误。谢谢你的提示。 –

相关问题