逐步执行代码或使用Run Sub/UserForm按钮,代码将按预期运行。但是,当我使用Command按钮(该按钮已分配了宏)时,代码将数据粘贴到已有的数据上,而不是追加。
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 = Range("T" & Rows.Count).End(xlUp).Row
你应该告诉VBA是使用工作表("Table")还是工作表("HAA")
相同:
If Range("A1").Value <> "Notes" Then
If Range("A1").Value = "Notes" Then