Insert new row in data table VBA Excel2010 ActiveX

ぃ、小莉子 提交于 2019-12-12 03:28:50

问题


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


来源:https://stackoverflow.com/questions/36639280/insert-new-row-in-data-table-vba-excel2010-activex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!