VBA code in single line including several ranges

Rayearth

Do I have to put every cells range in separate line, like this

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

or can I somehow include groups of columns (from certain cell all the way down) that are not next to each other in a single line? This code below doesn't seem to work for me.

Range("A6:B,G6:H" & Cells.SpecialCells(xlCellTypeLastCell).Row).HorizontalAlignment = xlLeft
Máté Juhász

You can use Union:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

vba code that is in several cells and checks several ranges

VBA For Each loop several ranges

Excel VBA hide several columns in 1 line of code

VBA Code Efficiency - excel Ranges

Union function not working on single cell ranges vba

Get contiguous date ranges grouped into a single line

Ranges - VBA - Why does this code not work?

How to create dynamic ranges and Improving vba Code

Code output in single line?

Autohotkey Single line code?

Difference between including module in single line vs multi line

Using VBA to create a single range from multiple ranges

Using single cell in loop as trigger to to copy multiple ranges VBA

How to set different colors in different ranges of one single line in R?

What reason(s) NOT to place multiple lines of VBA code on a single line separated by colons?

Compare and add in a single line of code?

Running a single line of code in PyCharm

Writing a function for a single line of code?

Is there a way to modify a line in this vba code?

What is the meaning of "No" in this line of code [VBA]

VBA code to put borders around merged cell ranges in dynamic sheet

R code for plotting multiple line segments with unique R ranges

Execute Python code line by line, like VBA?

Replace several consecutive lines with a single line using sed

How to decrement several variables in C++in a single line statement?

Declaration of multiple arrays on a single line in VBA

VBA: Single line if statement with multiple actions

Combine several single line text files into a single line text file in Unix

Python Convert multiple line code to a single line code