Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Sizing Text Boxes and Cells the Same.
Written by Allen Wyatt (last updated May 18, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
You already know that Excel allows you to create text boxes within your worksheets. You may have a need, at some point, to create a text box that is exactly the same size as a particular cell. If you only have one or two such text boxes to create, the easiest way is to follow these steps:
When you hold down the Alt key, it forces Excel to "snap" the sides of your text box to a drawing grid which just happens to match the cell boundaries in your worksheet. The result is a text box that is exactly the desired size.
If you need to create quite a few of these text boxes, all at one time, you can turn the snap-to-grid feature on permanently: Display the Page Layout tab of the ribbon, click the Align tool in the Arrange group, then click Snap To Grid.
If you have many, many such text boxes to create, on lots of different workbooks, you can create the desired text boxes using a macro. The following macro will create a text box directly over the selected cell and size it to be exactly the same size as the selected cell:
Sub TextBox2Cell() With ActiveCell ActiveSheet.Shapes.AddTextbox _ msoTextOrientationHorizontal, .Left, _ .Top, .Width, .Height End With End Sub
With a small change in the macro, you can modify it so that it will create text boxes that are just as large as whatever range of cells you have selected:
Sub TextBox2Selection() If TypeName(Selection) = "Range" Then With Selection ActiveSheet.Shapes.AddTextbox _ msoTextOrientationHorizontal, .Left, _ .Top, .Width, .Height End With End If End Sub
Regardless of which approach you use to create the text box (manual or macro), it should be noted that if you resize the cell by changing the column width or row height, the size of the text box will also change to match the new cell size.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11359) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Sizing Text Boxes and Cells the Same.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Want to search for text that may appear in a text box rather than in a regular worksheet cell? You can only perform the ...
Discover MoreWant to get rid of your text boxes and move their text into the worksheet? It's going to take a macro-based approach, ...
Discover MoreText boxes are easy to add to a worksheet and manually resize, as needed. If you want to resize the text box in a macro, ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2024-05-18 06:32:16
Kiwerry
If you don't want a manually created shape to move or size when column widths or row heights are changed, right-click the shape and navigate to Size and Position in the context menu, then look for "Properties", where you can select "Move but don't size" or "Free floating" as you prefer.
If you are using a macro, change the Placement property of the shape to the appropriate option, for example:
'============================================================================
Private Sub TextBox2Cell()
'============================================================================
Dim CShp As Shape
With ActiveCell
Set CShp = ActiveSheet.Shapes.AddTextbox _
(msoTextOrientationHorizontal, .Left, _
.Top, .width, .height)
End With
CShp.Placement = xlMove
End Sub
'============================================================================
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments