0
テーブルの最後に列を追加します。最初の見出しとその下の列の数式。次に、リスト全体の数式を自動入力します。私は変数宣言が問題だと信じています。一番下の自動入力セクションでエラーが表示されます。Excel VBA範囲変数とオートフィル
Dim LastCol As Long, lastrow As Long
Dim OOSCol As Long, LCell As Long
Dim LRange As Range
Dim ws As Worksheet
Set ws = Application.ActiveWorkbook.ActiveSheet
With ws
.Name = "Summary"
LastCol = .Cells(51, .Columns.Count).End(xlToLeft).Column
.Cells(51, LastCol + 1).Value = "OOS NO SOO"
.Cells(52, LastCol + 1).FormulaR1C1 = "=IF((RC[-21]=4)*AND(RC[-20]=0)*AND(RC[-19]=0)*AND(RC[-3]=""Roster"")*AND(RC[-4]=""Listed""),1,"""")"
.Cells(51, LastCol + 2).Value = "OOS SOO"
.Cells(52, LastCol + 2).FormulaR1C1 = "=IF((RC[-22]=4)*AND(RC[-21]>0)*AND(RC[-20]>0)*AND(RC[-4]=""Roster"")*AND(RC[-5]=""Listed""),1,"""")"
.Cells(51, LastCol + 3).Value = "SOH NO SOO"
.Cells(52, LastCol + 3).FormulaR1C1 = "=IF((RC[-23]=4)*AND(RC[-22]>0)*AND(RC[-21]=0)*AND(RC[-5]=""Roster"")*AND(RC[-6]=""Listed""),1,"""")"
.Cells(51, LastCol + 4).Value = "Negative Stock"
.Cells(52, LastCol + 4).FormulaR1C1 = "=IF((RC[-24]=4)*AND(RC[-23]<0)*AND(RC[-6]=""Roster"")*AND(RC[-7]=""Listed""),1,"""")"
.Cells(51, LastCol + 5).Value = "Overstock"
.Cells(52, LastCol + 5).FormulaR1C1 = "=IF((RC[-25]=4)*AND(RC[-21]>14)*AND(RC[-7]=""Roster"")*AND(RC[-8]=""Listed""),1,"""")"
.Cells(51, LastCol + 6).Value = "Dormant Stock"
.Cells(52, LastCol + 6).FormulaR1C1 = "=IF((RC[-26]=4)*AND(RC[-25]>0)*AND(RC[-24]>10)*AND(RC[-8]=""Roster"")*AND(RC[-9]=""Listed""),1,"""")"
.Cells(51, LastCol + 7).Value = "Outdated Stock Counts"
.Cells(52, LastCol + 7).FormulaR1C1 = "=IF((RC[-27]=4)*AND(RC[-26]<>0)*AND(RC[-17]>30)*AND(RC[-9]=""Roster"")*AND(RC[-10]=""Listed""),1,"""")"
.Cells(51, LastCol + 8).Value = "Total Issues"
.Cells(52, LastCol + 8).FormulaR1C1 = "=SUM(RC[-7]:RC[-1])*AND(RC[-10]=""Roster"")*AND(RC[-11]=""Listed"")"
.Range("A51", Cells(51, Columns.Count).End(xlToRight)).SpecialCells(xlCellTypeConstants).Interior.Color = RGB(0, 32, 96)
.Range("A51", Cells(51, Columns.Count).End(xlToRight)).SpecialCells(xlCellTypeConstants).Font.Color = vbWhite
End With
With ws
LastCol = .Cells(51, .Columns.Count).End(xlToLeft).Column
OOSCol = .Cells(52, LastCol - 8)
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
LCell = .Cells(lastrow, LastCol)
End With
LRange = Range(OOSCol, LCell).Select
Selection.AutoFill Destination:=Range(OOSCol, LCell)
エラーは何ですか? – kaza
'Range'は2つの数値パラメータを受け入れません。 'OOSCol'と' LCell'は 'Long'数値ではなく' Range'オブジェクトを意味しましたか? 'Select'の結果(' Select'はオブジェクトを返さない)に 'Range'を割り当てることはできませんが、可能ならば' Set LRange = ... 'と言う必要があります。 (そして、私はオートフィルを使用しませんが、元の選択と同じであるオートフィルを行うのは変です。[しかし、私はExcelで見知らぬものを見たことがありますので、あなたがそれを行う方法です) – YowE3K
Cell(52、LastCol + 1).Resize(1,8).AutoFill _ Destination:=範囲(Cells(52、LastCol + 1)、Cells(lastrow、LastCol + 8))のコードで修正されました。返信ありがとう –