每周,我都会从外部来源导入原始excel数据。我通常将它们粘贴为值,以便维护它们需要放入的表。每周运行此脚本来纠正一些格式问题,例如将select列更改为数字或日期然后进行排序(对于我拥有的数组)。但是,当我运行此命令时,它将选择整个列(总共两列),因此在脚本运行时,它将表扩展到数千行,并在以后的枢轴中提供错误的数据。我需要修改“列”选择代码,但不确定如何。
一个大问题是这些列中有几个没有数据的单元格。如果可能的话,应该在TABLE中选择该列的所有行,因为该脚本要等到输入新数据后才运行,并且已经更改了表的大小。
我记录了创建此脚本所需的操作,这意味着它不是非常优化,但是可以完成工作并且足够快。我尝试了以下代码,但我认为它不能替代Columns.ActiveSheet.Range(“ C2”,ActiveCell.SpecialCells(xlLastCell))。Select
Sub WeeklyRoutine()
'
' WeeklyRoutine Macro
'
'
Sheets("PR Raw Data").Select
Columns("EN:EN").Select
Selection.TextToColumns Destination:=Range( _
"BurnData[[#Headers],[est_po_place]]"), DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _
False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 3) _
, TrailingMinusNumbers:=True
Range("EN2").Select
ActiveWorkbook.Worksheets("PR Raw Data").ListObjects("BurnData").Sort. _
SortFields.Clear
ActiveWorkbook.Worksheets("PR Raw Data").ListObjects("BurnData").Sort. _
SortFields.Add Key:=Range("EN2"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("PR Raw Data").ListObjects("BurnData").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Current Week - SMPP Data").Select
Columns("C:C").Select
Selection.TextToColumns Destination:=Range("SMPPTrend[[#Headers],[PR]]"), _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter _
:=False, Tab:=True, Semicolon:=False, Comma:=False, Space:=False, _
Other:=False, FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
Columns("I:I").Select
Selection.TextToColumns Destination:=Range("SMPPTrend[[#Headers],[PR Age]]") _
, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Columns("H:H").Select
Selection.TextToColumns Destination:=Range( _
"SMPPTrend[[#Headers],[Est PO Place Dt]]"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 3), TrailingMinusNumbers:=True
Selection.NumberFormat = "m/d/yyyy"
Range("H2").Select
ActiveWorkbook.Worksheets("Current Week - SMPP Data").ListObjects("SMPPTrend"). _
Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Current Week - SMPP Data").ListObjects("SMPPTrend"). _
Sort.SortFields.Add Key:=Range("H2"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Current Week - SMPP Data").ListObjects( _
"SMPPTrend").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub