- 11
- 0
- 约3.17千字
- 约 3页
- 2017-09-02 发布于浙江
- 举报
终极解决EXCEL不同单元格格式太多的问题
终极解决EXCEL“不同单元格格式太多”的问题
2009-06-24 14:35
在格式超过4000的Excel表里录制一个新宏,内容如下所示:
Sub DeleteUnusedCustomNumberFormats()Dim Buffer As ObjectDim Sh As ObjectDim SaveFormat As VariantDim fFormat As VariantDim nFormat() As VariantDim xFormat As LongDim Counter As LongDim Counter1 As LongDim Counter2 As LongDim StartRow As LongDim EndRow As LongDim Dummy As VariantDim pPresent As BooleanDim NumberOfFormats As LongDim AnswerDim c As ObjectDim DataStart As LongDim DataEnd As LongDim AnswerText As StringNumberOfFormats = 1000ReDim 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 FinitoOn Error GoTo FinitoWorksheets.Add.Move after:=Worksheets(Worksheets.Count)Worksheets(Worksheets.Count).Name = CustomFormatsWorksheets(CustomFormats).ActivateSet Buffer = Range(A2)Buffer.SelectnFormat(0) = Buffer.NumberFormatLocalCounter = 1DoSaveFormat = Buffer.NumberFormatLocalDummy = Buffer.NumberFormatLocalDoEventsSendKeys {tab 3}{down}{enter}Application.Dialogs(xlDialogFormatNumber).Show DummynFormat(Counter) = Buffer.NumberFormatLocalCounter = Counter + 1Loop Until nFormat(Counter - 1) = SaveFormatReDim Preserve nFormat(0 To Counter - 2)Range(A1).Value = Custom formatsRange(B1).Value = Formats used in workbookRange(C1).Value = Formats not usedRange(A1:C1).Font.Bold = TrueStartRow = 3EndRow = 16384For Counter = 0 To UBound(nFormat)Cells(StartRow, 1).Offset(Counter, 0).NumberFormatLocal = nFormat(Counter)Cells(StartRow, 1).Offset(Counter, 0).Value = nFormat(Counter)Next CounterCounter = 0For Each Sh In ActiveWorkbook.WorksheetsIf Sh.Name = CustomFormats Then Exit ForFor Each c In Sh.UsedRange.CellsfFormat = c.NumberFormatLocalIf Application.WorksheetFunction.CountIf(Range(Cells(StartRow, 2), Cells(EndRow, 2)), fFormat) = 0 Then
您可能关注的文档
最近下载
- 专题2 数据采集与编码 学案(含解析)2025届高中信息技术.DOCX VIP
- 高中地理课件湘教版:1-1中国的人口和民族.ppt
- 鲁科版高中化学选择性必修1第3章物质在水溶液中的行为3.3.2沉淀溶解平衡的应用课件(内嵌音频+视频).ppt VIP
- 建筑施工安全管理论文【推荐】.doc VIP
- 2025年高考地理识图填图完全手册(扫描版).docx
- 防火封堵材料 GB23864-2023.pdf
- 专题2 数据采集与编码 课件 2025届高中信息技术.pptx VIP
- 专题1 数据与大数据 课件 2025届高中信息技术.pptx VIP
- 鲁科版高中化学选择性必修1第3章物质在水溶液中的行为3.3.1沉淀溶解平衡与溶度积(内嵌音频+视频).ppt VIP
- 2025年甘肃省高考物理试卷(含答案解析).docx VIP
原创力文档

文档评论(0)