创build一个新行并select一个单元格

我想让用户能够添加行到表单,但是我需要他们以编程方式执行,以便新行包含与已分配给它的macros的checkbox。

我的解决scheme是插入一个InputBox的行,这很好。

Dim rowloc As String rowloc = InputBox("Location to Insert Row", "What row do you want to insert the new row ABOVE?") Rows(rowloc).Select Selection.Insert Shift:=xlDown 

但是我有一段时间去那个行的列B并插入checkbox。 我在VBA中创build一个新button没有问题,只是到了另一个单元就是这个问题。

 Rows(rowloc).Offset(0, 1).Select 

也不起作用。 任何有用的提示或解决scheme?

Thw Rows(rowloc)是一个范围,包括行rowloc中的所有单元格。 如果您需要确定此范围内的单元格(在此行中),则例如,

 Rows(rowloc).Cells(2).Select ' in column 2 ("B") 

或者等同地,

 Rows(rowloc).Parent.Cells(rowloc,2).Select ' in column 2 ("B") 

要么

 ActiveSheet.Cells(rowloc,2).Select ' in column 2 ("B") ' might not be the same worksheet though, depending on your setup 

等等