A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Dear Arthur Primee,
Based on the description you provided, you would like to link a Text Box to a cell in Excel so that the cell or row/column automatically expands or shrinks when the Text Box size changes. In that case, please follow the steps below to run the VBA macro.
This is a custom workaround rather than an official Excel feature. It works on Excel desktop only (not Excel for the web), and the file must be saved as a macro-enabled workbook.
1.Select Insert > Text Box, then draw it over the cell you want to resize (for example, cell B6).
2.Select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm).
3.Add the macro
- Press Alt + F11 to open the VBA Editor.
- Select Insert > Module.
- If the new module already contains any text, press Ctrl + A and Delete to clear it.
- Paste the following code:
Sub FitCellToTextBox()
Dim shp As Shape
Dim cel As Range
Dim i As Integer
Set shp = ActiveSheet.Shapes(Application.Caller)
shp.Placement = xlFreeFloating
Set cel = shp.TopLeftCell
If shp.Height > 409.5 Then
cel.EntireRow.RowHeight = 409.5
Else
cel.EntireRow.RowHeight = shp.Height
End If
For i = 1 To 3
If cel.Width > 0 Then
cel.EntireColumn.ColumnWidth = cel.EntireColumn.ColumnWidth * shp.Width / cel.Width
End If
Next i
shp.Top = cel.Top
shp.Left = cel.Left
End Sub
4.Press Alt + Q to return to Excel, then save the file.
5.Assign the macro to the text box
- Right-click the border of the text box and select Assign Macro.
- Select FitCellToTextBox, then select OK.
Here is the result in my test environment after running the macro, where the cell resizes to match the text box:
Regarding your second question, "Alternatively, can a standard Excel cell automatically adjust its height and width dynamically as more text is typed into it, similar to how a text box behaves?", please refer to the answer provided by the AI assistant below.
Hope this helps. Thank you for your patience and your understanding. I'm looking forward for your reply.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.