单行VBA代码,包括多个范围


0

我是否必须将每个单元格范围放在单独的行中,就像这样

Range("A6:B" & Cells.SpecialCells(xlCellTypeLastCell).Row).HorizontalAlignment = xlLeft
Range("G6:H" & Cells.SpecialCells(xlCellTypeLastCell).Row).HorizontalAlignment = xlLeft

或者我可以以某种方式包括在一行中彼此不相邻的列组(从某些单元格一直向下)?以下代码似乎对我不起作用。

Range("A6:B,G6:H" & Cells.SpecialCells(xlCellTypeLastCell).Row).HorizontalAlignment = xlLeft

Answers:


1

您可以使用 Union

Union(Range("A6:B" & Cells.SpecialCells(xlCellTypeLastCell).Row), Range("G6:H" & Cells.SpecialCells(xlCellTypeLastCell).Row)).HorizontalAlignment = xlLeft


1
我修改它工作
Rayearth

正在寻找缩短整个代码的东西,但我猜你的想法符合我的查询标准。谢啦。
Rayearth
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.