简体   繁体   English

如何仅使用在VBA中With语句之后编写的代码

[英]How do I use only the code written after the With statement in VBA

I am using With/End With , and want to only call the code written after the With but I can't figure out how to do this. 我正在使用With/End With ,并且只想调用在With之后编写的代码,但是我不知道该怎么做。 For example: 例如:

With Activecell.End(xlToRight).End(xlToRight)
    Range(., .End(xlDown)).NumberFormat = "###0"
End With

I want the single . 我要单身. in this case to represent Activecell.End(xlToRight).End(xlToRight) but it doesn't work. 在这种情况下代表Activecell.End(xlToRight).End(xlToRight)但它不起作用。 Any ideas? 有任何想法吗?

Thanks! 谢谢!

Assuming that Active was intended to be ActiveCell , then the With ... End With will be dealing with a single cell. 假设Active本来是ActiveCell ,则With ... End With将处理单个单元格。 At a minimum, you need to tell Range that you want to deal with the .Cells (in this case a single cell) that is specified by the With ... End With statement. 至少,您需要告诉Range您要处理由With ... End With语句指定的.Cells (在这种情况下为单个单元格)。

With ActiveCell.End(xlToRight).End(xlToRight)
    Range(.Cells, .Cells.End(xlDown)).NumberFormat = "###0"
End With

If this was referring to a range of multiple cells, you should use .Cells(1, 1) but since it is by definition a single cell, specifying the position is unnecessary. 如果这是指多个单元格的范围,则应使用.Cells(1, 1)但由于按定义它是单个单元格,因此无需指定位置。

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

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