终极解决EXCEL不同单元格格式太多的问题.docVIP

  • 11
  • 0
  • 约3.17千字
  • 约 3页
  • 2017-09-02 发布于浙江
  • 举报

终极解决EXCEL不同单元格格式太多的问题.doc

终极解决EXCEL不同单元格格式太多的问题

终极解决EXCEL“不同单元格格式太多”的问题 2009-06-24 14:35 在格式超过4000的Excel表里录制一个新宏,内容如下所示: Sub DeleteUnusedCustomNumberFormats() Dim Buffer As Object Dim Sh As Object Dim SaveFormat As Variant Dim fFormat As Variant Dim nFormat() As Variant Dim xFormat As Long Dim Counter As Long Dim Counter1 As Long Dim Counter2 As Long Dim StartRow As Long Dim EndRow As Long Dim Dummy As Variant Dim pPresent As Boolean Dim NumberOfFormats As Long Dim Answer Dim c As Object Dim DataStart As Long Dim DataEnd As Long Dim AnswerText As String NumberOfFormats = 1000 ReDim nFormat(0 To NumberOfFormats) AnswerText = Do you want to delete unused custom formats from the workbook? AnswerText = AnswerText Chr(10) To get a list of used and unused formats only, choose No. Answer = MsgBox(AnswerText, 259) If Answer = vbCancel Then GoTo Finito On Error GoTo Finito Worksheets.Add.Move after:=Worksheets(Worksheets.Count) Worksheets(Worksheets.Count).Name = CustomFormats Worksheets(CustomFormats).Activate Set Buffer = Range(A2) Buffer.Select nFormat(0) = Buffer.NumberFormatLocal Counter = 1 Do SaveFormat = Buffer.NumberFormatLocal Dummy = Buffer.NumberFormatLocal DoEvents SendKeys {tab 3}{down}{enter} Application.Dialogs(xlDialogFormatNumber).Show Dummy nFormat(Counter) = Buffer.NumberFormatLocal Counter = Counter + 1 Loop Until nFormat(Counter - 1) = SaveFormat ReDim Preserve nFormat(0 To Counter - 2) Range(A1).Value = Custom formats Range(B1).Value = Formats used in workbook Range(C1).Value = Formats not used Range(A1:C1).Font.Bold = True StartRow = 3 EndRow = 16384 For Counter = 0 To UBound(nFormat) Cells(StartRow, 1).Offset(Counter, 0).NumberFormatLocal = nFormat(Counter) Cells(StartRow, 1).Offset(Counter, 0).Value = nFormat(Counter) Next Counter Counter = 0 For Each Sh In ActiveWorkbook.Worksheets If Sh.Name = CustomFormats Then Exit For For Each c In Sh.UsedRange.Cells fFormat = c.NumberFormatLocal If Application.WorksheetFunction.CountIf(Range(Cells(StartRow, 2), Cells(EndRow, 2)), fFormat) = 0 Then

文档评论(0)

1亿VIP精品文档

相关文档