Break a character string in a cell with a comma
In the previous article "Break a character string in a cell"
I introduced a code that breaks every five characters.
In this article, I will try on a method of breaking a line with a comma.
Since there may be more than one comma in the string,
From the first character to the last character string
I will judge with an If statement
Whether or not each character is equal to ","
If the character is equal to ","
We will add Chr (10) to the string as in the previous article.
Code here
Sub macro180609a()
Dim i As Integer |
Execute the above code in the state of the image below

Result:
Here are parts that were not broken by execution results.
The comma which did not break is full size when it sees well.
In the above code, it will only break at a half-size comma.
To pick up both half-size and full size commas
Use the "Or" operator for the condition of the If statement as follows.
c = "," Or c = ","
It returns True when c is either a half-size comma or a full-width comma.
Here is the code under this condition
Sub macro180609b() Dim i As Integer |
Execute the above code in the state of the image below

Result:
A line feed was made with a comma in both half size and full size.
You can use more than one "Or" operator side by side.
By specifying the condition of the If statement as follows,
The type of letter you want to break is increased.
c = "," Or c = "," Or c = "、"
Whether it is VBA or worksheet function,
There are many things that it will not work
because of differences between half size and full size.
It is troublesome.
| 固定リンク
この記事へのコメントは終了しました。

コメント