« セルに入力した文字をはみ出して表示させる | トップページ | 結合したセルの高さを自動調整する »

2018年7月22日 (日)

Display strings on the right side of cells

When entering a long character string in a cell in Excel
If nothing is entered in the right cell
Like the A1 cell of the image below
Characters are displayed on the right side.
Vba20180708a

In the image, the same character string is entered from A1 to A3 cell.
Even if nothing is entered in the right cell
Like the A2 cell
Characters may not be displayed on the right side.

This happens in the following cases.
· When cell formatting is checked
 "Show folded and show whole"
And
· When the cell height is not automatically adjusted

If the height of the cell is insufficient
The character string will not be displayed
and it will be cut in the middle.
It is a problem because characters are printed out in this state.

The A3 cell is in a state
the height of A2 cell is automatically adjusted.
The character string in that cell is
wrapped and displayed.

You want to display strings on the right side
like the A1 cell of the previous picture.
I will introduce macros that can be used in such cases.

Code here

Code that display strings on the right side of cells:

Sub macro180708a()
'Display strings on the right side of cells
'Before running this macro
'Select the range you want to adjust

    Dim obj As Object
   
    For Each obj In Selection
        'No cell merge
       If obj.MergeCells = False Then
            With obj
                'No wrapping
                .WrapText = False
                'No shrink
                .ShrinkToFit = False
            End With
             'Automatic cell height adjustment
            Rows (obj.Row).EntireRow.AutoFit
        End If
    Next
   
End Sub

Execute the above code in the state of the image below
Vba20180708b
Result:
Vba20180708c

I noticed this time writing this article
When "display by folding" is set in the merged cell,
the cell height is adjusted to one line.
So in the above code
I targeted only unmerged cells.

|

« セルに入力した文字をはみ出して表示させる | トップページ | 結合したセルの高さを自動調整する »

コメント

この記事へのコメントは終了しました。

トラックバック


この記事へのトラックバック一覧です: Display strings on the right side of cells:

« セルに入力した文字をはみ出して表示させる | トップページ | 結合したセルの高さを自動調整する »