跳到主要内容

如何在Excel中以cm(厘米)为单位设置单元格大小?

在工作表上,行高和列宽的默认单位是预设的,默认列宽为8.38个字符,默认行高为12.75点。 在Excel中,很难以英寸或厘米为单位设置行高或列宽。 但是,有时您出于某些目的需要将高度和宽度更改为厘米。 您如何解决这个问题?

使用VBA代码以cm(厘米)为单位设置像元大小

使用 Kutools for Excel 设置单元格大小以厘米(厘米)为单位好主意3


箭头蓝色右气泡 使用VBA代码以cm(厘米)为单位设置像元大小

除了使用VBA代码外,您无法使用Excel的功能以厘米为单位设置高度和宽度。 以下两个代码可以帮助您设置列宽和行高。 进行如下操作:

1.选择要以厘米为单位设置的单元格。

2。 点击 开发商 > Visual Basic中,一个新的 适用于应用程序的Microsoft Visual Basic 将显示一个窗口,单击 插页 > 模块,然后将以下代码输入到模块中:

设置行高(厘米)的代码:

Sub RowHeightInCentimeters()
Dim cm As Single
cm = Application.InputBox("Enter Row Height in Centimeters", _
"Row Height (cm)", Type:=1)
If cm Then
Selection.RowHeight = Application.CentimetersToPoints(cm)
End If
End Sub

3。 然后点击 文档乘法计算 3 按钮执行代码。 然后会弹出一个提示框,告诉您输入多个行高。 看截图:

文档设置单元格大小 cm1

备注:输入的数字必须小于15。如果在此对话框中输入0,则此VBA代码不会更改行高。

4。 点击 OK。 所选单元格的行高已设置为2厘米。 看截图:

文档设置单元格大小 cm2 -2 文档设置单元格大小 cm3

如果还要以厘米为单位设置列宽,则可以输入以下代码:

设置列宽(厘米)的代码:

Sub ColumnWidthInCentimeters()
Dim cm As Single, points As Integer, savewidth As Integer
Dim lowerwidth As Integer, upwidth As Integer, curwidth As Integer
Dim Count As Integer
Application.ScreenUpdating = False
cm = Application.InputBox("Enter Column Width in Centimeters", _
"Column Width (cm)", Type:=1)
If cm = False Then Exit Sub
points = Application.CentimetersToPoints(cm)
savewidth = ActiveCell.ColumnWidth
ActiveCell.ColumnWidth = 255
If points > ActiveCell.Width Then
MsgBox "Width of " & cm & " is too large." & Chr(10) & _
"The maximum value is " & _
Format(ActiveCell.Width / 28.3464566929134, _
"0.00"), vbOKOnly + vbExclamation, "Width Error"
ActiveCell.ColumnWidth = savewidth
Exit Sub
End If
lowerwidth = 0
upwidth = 255
ActiveCell.ColumnWidth = 127.5
curwidth = ActiveCell.ColumnWidth
Count = 0
While (ActiveCell.Width <> points) And (Count < 20)
If ActiveCell.Width < points Then
lowerwidth = curwidth
Selection.ColumnWidth = (curwidth + upwidth) / 2
Else
upwidth = curwidth
Selection.ColumnWidth = (curwidth + lowerwidth) / 2
End If
curwidth = ActiveCell.ColumnWidth
Count = Count + 1
Wend
End Sub

箭头蓝色右气泡 使用 Kutools for Excel 设置单元格大小以厘米(厘米)为单位

有了上述代码,您只能以厘米为单位设置像元大小,今天,我将向您介绍一个多功能工具, Kutools for Excel 它不仅可以设置厘米大小,还可以设置英寸,磅和像素。

Kutools for Excel, 与超过 300 方便的功能,使您的工作更加轻松。 

安装后 Kutools for Excel,请执行以下操作:(立即免费下载Kutools for Excel!)

1.突出显示要设置的单元格(以厘米为单位)。

2。 点击 Kutools > Format > Adjust Cell Size,请参见屏幕截图:

doc设定储存格大小cm9

3.在 Adjust Cell Size 对话框中选择 Unit type 您需要并指定 Row heightColumn widthSet values 部分。 看截图:

doc以cm 5为单位设置单元格大小

4。 然后点击 OK or 使用。 您将获得具有2 cm行高和3cm列宽的单元格。

文档设置单元格大小 cm6


箭头蓝色右气泡 使用 Kutools for Excel 设置单元格大小以厘米(厘米)为单位

Kutools for Excel:300 + Excel 中必须具备的功能, 从这里免费试用30天。

相关文章:

设置范围的列宽和行高

如何在Excel中对多个单元格求平方?

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (4)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thank you. I used your idea to compare ColumnWidth and Width, and it was very helpful. I did this function in Object Pascal and want to share it with you. Thanks. procedure ActiveCellColumnWidthInCentimeters(ExcelApp: Variant; CM: Double); var dColumnWidth, dWidth, points: Double; begin dColumnWidth := ExcelApp.ActiveCell.ColumnWidth; dWidth := ExcelApp.ActiveCell.Width; points := ExcelApp.CentimetersToPoints(CM); ExcelApp.ActiveCell.ColumnWidth := ((points * dColumnWidth) / dWidth); end;
This comment was minimized by the moderator on the site
Seems redundant. Just go into the regular column size dialogue and add "cm" after typing the size.
This comment was minimized by the moderator on the site
Needed this badly. Thank you so much!
This comment was minimized by the moderator on the site
Wow - that is awesome! I needed to set cells to print at a certain size. I have never been able to figure out how to do that before. Yay for VBA!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations