Insert new row in data table VBA Excel2010 ActiveX

2019-09-12 05:22发布

问题:

I want to insert a row in my data table. When I try it manually (select row, insert new row) it works just fine, but when I try to add it into my macro, which is inside an ActiveX button(!) it says "Runtime error 438: Object does not suppoort this method". If I try the mecro in a usual macro, not inside the button, it works fine aswell.

How can I get rid of this problem?

Set wsd = Sheets("Data")
wsd.Select                      
With wsd
.Rows("5:5").Select
.Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 'Here appears the error
End With

Help is much appreciated. Thanks in advance!

回答1:

You don't need Select. Not for the sheet and not for the row.

Sub test()
Set wsd = Sheets("Data")
With wsd
    .Rows("5:5").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 
End With

End Sub