excel - Excel - 下标超出范围
问题描述
语境:
我正在将数据库中的数据导出为 .csv 文件,将其复制到主工作簿,格式化数据,然后将格式化的数据复制到另一张工作表。
错误代码:
ActiveWorkbook.Worksheets("Sheet3").AutoFilter.Sort.SortFields.Clear
如下图所示:
Sub weekly_export_cleanup()
'
' weekly_export_cleanup Macro
'
'
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Columns("H:L").Select
Selection.Delete Shift:=xlToLeft
Columns("J:K").Select
Selection.Delete Shift:=xlToLeft
Columns("K:Q").Select
Selection.Delete Shift:=xlToLeft
Cells.Select
Cells.EntireColumn.AutoFit
Columns("D:D").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="(PO", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("D1").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("Sheet3").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet3").AutoFilter.Sort.SortFields.Add(Range( _
"D1:D15"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = _
RGB(255, 199, 206)
With ActiveWorkbook.Worksheets("Sheet3").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
解决方案
推荐阅读
- batch-file - 使用 Findstr 批量查找具有非 ASCII 字符的字符串
- cv2 - 为什么 cv2.rectangle() 不支持浮点值?
- python - 删除双重文件内容
- php - 如何使用表单、输入和 php 更新一些占位符文本?
- javascript - 如何将模板文字的结果保存到对象中?
- npm - 安装vue-cli时如何修复错误
- python-3.x - 错误:找不到满足要求 tensorflow 的版本(来自版本:无)
- c# - .net Core 3.0 中的 Aes 加密“指定的密钥不是此算法的有效大小。”
- android - 应用程序在 IllegalArgumentException 后被杀死
- mysql - 无法在 ubuntu 19.04 上安装 libzip4