9 行目で「添え字が範囲外です」というエラーが表示されます。私はプログラマーではなく、そうであるとは主張していません。このため、Excel ボタンを機能させるために少し助けが必要です。私はVBを少ししか知りません。ボタンが特定のポイントまでマクロを実行し、その後このエラーが発生するため、私は途方に暮れています...
------Line 9:ActiveWorkbook.Worksheets("strActiveWorksheet").Sort.SortFields.Clear-----
コードは次のとおりです。
'
' MakeParetoTable Macro
'
Dim strActiveWorkSheet As String
Sub MakeParetoTable()
strActiveWorkSheet = ActiveSheet.Name
Range("B6:B31,I6:I31").Select
Range("Table2[[#Headers],[Total Quanity]]").Activate
Selection.Copy
Range("P6").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("P:P").EntireColumn.AutoFit
ActiveWindow.ScrollColumn = 2
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("strActiveWorksheet").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("strActiveWorksheet").Sort.SortFields.Add Key:=Range("Q7:Q31"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("strActiveWorksheet").Sort
.SetRange Range("P6:Q31")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Application.WindowState = xlMinimized
Application.WindowState = xlNormal
Range("Q32").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-25]C:R[-1]C)"
Range("Q33").Select
ActiveWindow.SmallScroll ToRight:=1
Range("R7").Select
ActiveCell.FormulaR1C1 = "=RC[-1]/R32C17"
Range("R7").Select
Selection.AutoFill Destination:=Range("R7:R31"), Type:=xlFillDefault
Range("R7:R31").Select
Range("S7").Select
ActiveCell.FormulaR1C1 = "=RC[-1]"
Range("S8").Select
ActiveCell.FormulaR1C1 = "=R[-1]C+RC[-1]"
Range("S8").Select
Selection.AutoFill Destination:=Range("S8:S31"), Type:=xlFillDefault
Range("S8:S31").Select
End Sub