コードをステップ実行するか、Run Sub/UserFormボタンを使用すると、コードは意図したとおりに機能します。しかし、私はコマンドボタン(割り当てられているマクロを持っている)を使用すると、コードは既存のデータの上にデータを貼り付けます。コードによるステップ実行と実行が機能します。ただし、コマンドボタンを使用すると正しく機能しません。
Sub Testing()
Application.ScreenUpdating = False
Dim tt As Range
Dim tt2 As Range
Dim LR As Long
Set tt = ThisWorkbook.Sheets("Table").UsedRange
Set tt2 = ThisWorkbook.Sheets("HAA").UsedRange
LR = Range("T" & Rows.Count).End(xlUp).Row
tt.AutoFilter
tt.AutoFilter 12, "already associated"
If Range("A1").Value <> "Notes" Then
tt.Copy
tt2.Range("B1").PasteSpecial xlPasteValues
tt2.Range("A1").Value = "Notes"
Else
If Range("A1").Value = "Notes" Then
tt.Offset(1, 0).Copy
With tt2
.Range("A" & LR).Offset(1, 1).PasteSpecial xlPasteValues
End With
End If
End If
With tt2
.AutoFilter
.Columns.AutoFit
.AutoFilter
End With
With tt2.Font
.Name = "Arial"
.Size = 8
End With
Application.ScreenUpdating = True
Sheets("HAA").Activate
End Sub
'LR = ... 'の後に次のコードを追加できますか? e 'MsgBox LR'を実行し、その変数の計算量を報告しますか? – nbayly
行4は、ペーストの正しい行です。オフセットが使用された後。 – FonR
コマンドボタンはどのシートですか? – nbayly