跳到主要內容

如何在Excel中以cm(厘米)為單位設置單元格大小?

在工作表上,行高和列寬的默認單位是預設的,默認列寬為8.38個字符,默認行高為12.75點。 在Excel中,很難以英寸或厘米為單位設置行高或列寬。 但是,有時您出於某些目的需要將高度和寬度更改為厘米。 您如何解決這個問題?

使用VBA代碼以cm(厘米)為單位設置像元大小

使用Kutools for Excel以cm(厘米)為單位設置單元格大小好主意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以cm(厘米)為單位設置單元格大小

有了上述代碼,您只能以厘米為單位設置像元大小,今天,我將向您介紹一個多功能工具, Excel的Kutools 它不僅可以設置厘米大小,還可以設置英寸,磅和像素。

Excel的Kutools, 與以上 300 方便的功能,使您的工作更加輕鬆。 

安裝後 Kutools for Excel,請執行以下操作:(立即免費下載Kutools for Excel!)

1.突出顯示要設置的單元格(以厘米為單位)。

2。 點擊 Kutools > Format > Adjust Cell Size,請參見屏幕截圖:

doc設定儲存格大小cm9

3。 在裡面 Adjust Cell Size 對話框中選擇 Unit type 您需要並指定 Row heightColumn width Set values 部分。 看截圖:

doc以cm 5為單位設置單元格大小

4。 然後點擊 OK or 登記。 您將獲得具有2 cm行高和3cm列寬的單元格。

文檔設置單元格大小 cm6


箭頭藍色右氣泡 使用Kutools for Excel以cm(厘米)為單位設置單元格大小

Kutools for Excel:您必須在Excel中擁有300多種功能, 從這裡免費試用30天。

相關文章:

設置範圍的列寬和行高

如何在Excel中對多個單元格求平方?

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為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