简体   繁体   English

其他工作表上Excel范围的VBA代码

[英]vba code for excel range on other sheet

I try to use below VBA code to delete a range of data on other sheet, but it deleted data on sheet1 instead. 我尝试使用下面的VBA代码删除其他工作表上的一系列数据,但它删除了sheet1上的数据。 Can someone help for this? 有人可以帮忙吗?

With Sheets("Found")
  lr = .Range("A" & Rows.Count).End(xlUp).Row
  Range(Cells(2, 1), Cells(lr, 5)).Clear
End With

Thanks 谢谢

Put a period. 放一段。

With Sheets("Found")
  lr = .Range("A" & Rows.Count).End(xlUp).Row
  .Range(.Cells(2, 1), .Cells(lr, 5)).Clear
End With

Minor typo when referring to your worksheet object. 引用工作表对象时的小错字。

On line 3, you didn't associate your Range with Sheets("Found") because you are missing the . 在第3行,您没有将Range与Sheets("Found")关联,因为您缺少. in front of Range(Cells(2, 1), cELLS(LR, 5)).Clear . Range(Cells(2, 1), cELLS(LR, 5)).Clear

Should look like this: 应该看起来像这样:

With Sheets("Found")
  lr = .Range("A" & .Rows.Count).End(xlUp).Row
  .Range(.Cells(2, 1), .Cells(lr, 5)).Clear
End With

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

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