简体   繁体   English

从范围中删除一个单元格

[英]remove one cell from a range

I want to delete first cell of H column of a table set as rng8 and put the new object in rng9. 我想删除设置为rng8的表的H列的第一个单元格,然后将新对象放入rng9。 The cell I want to exclude is the header of the column. 我要排除的单元格是列的标题。 I use below commands but they don't work 我使用以下命令,但它们不起作用

Set rng8 = Sheets(firstsheetname).Range("H:H") 

Set rng9 = rng8.Offset(1, 0).Resize(rng8.Rows.Count - 1, rng8.Columns.Count)

You are experiencing an error because when you try to offset the whole column by one row down, there is no further row below (since you have selected the whole column). 您遇到错误是因为,当您尝试将整列向下偏移一行时,下面没有其他行(因为您选择了整列)。
Based solely on your question and code, this works: 根据您的问题和代码,此方法有效:

Set rng8 = Sheets(firstsheetname).Range("H:H") 
Set rng9 = rng8.Cells(1,1).Offset(1, 0).Resize(rng8.Rows.Count - 1, rng8.Columns.Count)

In fact, if you actually do not need rng8 then you can set rng9 thus: 实际上,如果您实际上不需要rng8则可以这样设置rng9:

With Sheets(firstsheetname)
    Set rng9 = .Range("H2:H", & .Rows.Count)
End With

However, as someone commented, if you are interested only in setting up to the last used row of Column H, then use this: 但是,正如某人评论的那样,如果您只对设置H列的最后使用行感兴趣,请使用以下命令:

With Sheets(firstsheetname)
    Set rng9 = .Range("H2", .Range("H" & .Rows.Count).End(xlUp))
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM