我已经编写了一个要在团队之间共享的代码,该代码将获取一些库存数据,进行一些格式化和计算,以使您对现有库存有个清晰的了解,然后输入yadda yadda yadda。
该代码在我的计算机上以及其他29个人的计算机中的大约27处都能完美运行。我有两个团队成员在同一步骤中遇到相同的错误。所讨论的代码行旨在对现有库存周进行排序,从最小到最大,有问题的孩子到全班同学。
他们得到了
错误438对象不支持此属性或方法。
简单的解决方法是从脚本中删除此部分代码,并让他们手动执行此步骤,这对他们来说足够好且容易。但是,我仍然想让我的代码正常工作,我想提供一个真正的解决方案,而不是“嗯,我想我们只是跳过那一部分”。
我在网上看到的可能的解决方案与excel版本有关,我使用的是365,并且它们可能仍在使用2016。但是,我确定27个没有错误的其他应用程序也都使用了2016。
下面是整个代码的副本,我突出显示了错误的步骤。任何帮助,将不胜感激。
'''Sub IA_Script()
'
' IA_Script Macro
'
'
Columns("AS:AS").Select
Selection.Cut
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
'Remove the buyer column and replace it at the begining of the sheet
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
'Remove the OpCo column
Columns("Y:Y").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("Y1").Select
ActiveCell.FormulaR1C1 = "4 Week Usage"
Range("Y2").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[27]:RC[30])"
Range("Y3").Select
'Insert 4 week usage colmun
Selection.NumberFormat = "0.00"
'Format numbers to be more readable
Columns("Z:Z").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("Z1").Select
ActiveCell.FormulaR1C1 = "Weeks on Hand"
Range("Z2").Select
'Insert weeks on hand colmun
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-2]/RC[-1]"
'Insert weeks on hand formula, ASOH divided by 4 week usage
Selection.NumberFormat = "0.00"
'Format numbers to be more readable
lastrow = ActiveSheet.Range("A65536").End(xlUp).Row
Range("Y2:Y2").Select
Selection.AutoFill Destination:=Range("Y2:Y" & lastrow), Type:=xlFillDefault
'Auto fill the 4 week usage colmun to the last row
lastrow = ActiveSheet.Range("A65536").End(xlUp).Row
Range("Z2:Z2").Select
Selection.AutoFill Destination:=Range("Z2:Z" & lastrow), Type:=xlFillDefault
'Auto fill the weeks on hand usage to the last row
Range("C1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("C1").Select
'Remove the contents from the column
ActiveCell.FormulaR1C1 = "Notes"
'Rename the column Notes column
Columns("D:H").Select
Selection.Delete Shift:=xlToLeft
Columns("G:J").Select
Selection.Delete Shift:=xlToLeft
Range("K:K,M:M,N:N").Select
Range("N1").Activate
Selection.Delete Shift:=xlToLeft
Columns("R:R").Select
Selection.Delete Shift:=xlToLeft
Columns("S:AA").Select
Selection.Delete Shift:=xlToLeft
'Remove the excess colmuns
Range("T1").Select
ActiveCell.FormulaR1C1 = "Phase Out"
Range("C2").Select
ActiveCell.FormulaR1C1 = "=IFERROR(INDEX(RC[16],MATCH(R1C20,RC[17],0),1),"""")"
Range("T1").Select
Range("C2").Select
Selection.AutoFill Destination:=Range("C2:C5205")
Range("C2:C5205").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Formula to select just the cells that are a phase out and move them over to colmun C
Columns("S:X").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
'Removing more excess data
Columns("T:W").Select
Selection.Delete Shift:=xlToLeft
'Removing more data
Columns("T:AC").Select
Selection.ColumnWidth = 4.43
'Sizing the movement columns smaller
Columns("AD:AK").Select
Selection.Delete Shift:=xlToLeft
'Removing the last of the excess data
Rows("1:1").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'Wrap the text in the first row
*****Range("N1").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("Multi IA").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Multi IA").AutoFilter.Sort.SortFields.Add2 Key:= _
Range("N1:N2205"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Multi IA").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
**End With
'Sort the weeks on have column smallest to largest***
Columns("G:G").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="I", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = False
'Conditionally format cells with an I to yellow
Range("AE1").Select
ActiveCell.FormulaR1C1 = "Phasing To"
Range("AE2").Select
Columns("D:D").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""","""",R1C32&"" ""&RC[-1])"
Range("D3").Select
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D2205")
Range("D2:D2205").Select
Selection.Copy
Range("C2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("D:D").Select
Application.CutCopyMode = False
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("C:C").EntireColumn.AutoFit
'Add the words phasing to in front of the sub number, copy the data over to the exisiting cell and clean up
Range("H1").Select
ActiveSheet.UsedRange.AutoFilter Field:=8, Criteria1:="=S", _
Operator:=xlOr, Criteria2:="="
'Remove Remote stock items
Rows("2:1048576").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$I2=1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 12611584
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
'format demand items blue
Cells.Select
Cells.EntireColumn.AutoFit
'Autofit the entire worksheet
Range("C1").Select
ActiveCell.FormulaR1C1 = "Notes"
'Rename the column Notes column
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
'freeze the top row
End Sub