运行时错误13类型不匹配**名称=范围(" A2" + i)**

时间:2014-11-25 19:00:40

标签: runtime-error

所以我正在尝试创建一个宏,根据字符串的长度为字符串添加空格,并且我不断收到运行时错误13类型不匹配。有什么建议?提前谢谢!

Option Explicit 
Sub AddSpacesToNames() 
Dim Names As String, TotalNames As Integer, i As Integer  

TotalNames = Application.WorksheetFunction.CountA(Range("A2", Range("A2").End(xlDown)))  

For i = 1 To TotalNames     
    **Names = Range("A2" + i)**     
    If Len(Names) >= 11 And Len(Names) <= 12 Then         
        Names = (" " & Names)     
    ElseIf Len(Names) >= 9 And Len(Names) <= 10 Then         
        Names = ("  " & Names)     
    ElseIf Len(Names) >= 7 And Len(Names) <= 8 Then         
        Names = ("   " & Names)     
    ElseIf Len(Names) >= 5 And Len(Names) <= 6 Then         
        Names = ("    " & Names)     
    ElseIf Len(Names) >= 3 And Len(Names) <= 4 Then         
        Names = ("     " & Names)     
    ElseIf Len(Names) >= 1 And Len(Names) <= 2 Then         
        Names = ("      " & Names)     
    End If 
Next i  

End Sub

0 个答案:

没有答案