Rotate cell contents 90 degrees, -90 degrees and 180 degrees
There is an opportunity to use Excel to make a seat chart, an arrangement map of the office and so on.
"I made up my mind what I should make it upwards, but I made it for the time"
"The opposite direction was better after all"
Or
"It is difficult to see the seat table as seen from the seat where I sit.
"So, I want to change the direction of it.
Have you ever thought about the above?
In such a case,
You should want to rotate the contents of the cell by 90 degrees or 180 degrees (clockwise as positive
direction).
I would like to make a macro that can be used in such cases.
To rotate cell contents by 90 degrees
What kind of operation is required?
Please look at the figure below.
What is the operation necessary to rotate the arrangement on the left by 90 degrees and place it like
the right side?
First, the rows on the left (A, B, C, D) are in the direction of the column.
The first row (A, B, C, D) before change is the second row.
The second row is in the direction of the column, as same as the former first row.
the second row before the change is The first column.
In other words,
you can swap rows and columns and reverse the columns themselves
It is to rotate cell contents by 90 degrees.
Rotation by -90 degrees is as shown below
Swap rows and columns
Make the contents of the column reverse.
The operation of rotating by 90 degrees is
the same as swapping rows and columns or putting them in reverse order.
It is a strange feeling that rotation can be done by swapping.
Next I will think about the operation to rotate by 180 degrees.
Please see the figure below.
The first row (A, B, C, D) is in reverse order
Furthermore, the columns themselves are also in reverse order.
To do this with VBA
Make the contents of the columns reverse
Reverse the order of each column.
In the case of 180 degree rotation,
Do not swap rows and columns
but make it in reverse order.
To do these operations with VBA,
After storing the selected range in the array
We will exchange with For statements and UBound.
For the method of storing the contents of the cell in an array
Please also refer to this article.
『Store cell values in
arrays』
Code here
Sub macro180211a() Dim i As Integer, j As
Integer |
Sub macro180211b() Dim i As Integer, j As
Integer |
Sub macro180211c() Dim i As Integer, j As
Integer |
By the way
to make it a mirror image,
To make a mirror image in the row direction, reverse the cell contents of the row.
In the column direction, reverse the cell contents of the column.
If you are interested, please modify the above code and make it.
| 固定リンク
| コメント (0)
| トラックバック (0)
