2015-12-23 25 views
1

我只想讓我的cells只顯示最後100個字符。在Excel中隱藏字符,我收到錯誤:無法設置Range類的NumberFormat屬性

這裏是我的代碼:

Sub HideCharacters() 
    Dim DQ As String, mesage As String 
    On Error GoTo Errorcatch 
    DQ = Chr(34) 
    For Each r In Selection 
     mesage = Right(r.Value, 100) 
     mesage = DQ & mesage & DQ 
     r.NumberFormat = ";;;" & mesage 
    Next r 
Errorcatch: 
MsgBox Err.Description 
End Sub 

代碼工作了一會兒,然後我添加更多的工作表,並應用宏他們,我開始得到錯誤:「Unable to set the NumberFormat property of the Range class」,如何解決這個?

謝謝你在前進, -Matt

回答

1

來源:

https://support.office.com/en-my/article/Excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3

Number formats in a workbook

Between 200 and 250, depending on the language version of Excel that you have installed

在我的Excel 2010中失敗的第207位的格式:

Sub Tester() 
    Dim c As Range 
    For Each c In Range("A1:A1000") 
     c.NumberFormat = ";;;""" & c.Address(False, False) & """" 
    Next c 
End Sub 
+0

好解釋爲什麼它失敗了,謝謝。你能幫我解決這個問題嗎? – Matt

+0

除了使用隱藏的列和公式來顯示最後100個字符,或者將文本存儲在單元格註釋中,並使用VBA將其填充回選定的單元格之外,我想不出有什麼辦法。 –

相關問題