ไปยังเนื้อหาหลัก

วิธีปรับขนาดรูปภาพให้พอดีกับเซลล์ใน Excel

โดยปกติรูปภาพที่แทรกจะลอยอยู่เหนือเซลล์และส่วนใหญ่แล้วรูปภาพหนึ่งภาพจะครอบคลุมเซลล์จำนวนมาก หากเวิร์กชีตมีรูปภาพจำนวนมากคุณอาจต้องใส่รูปภาพแต่ละรูปลงในเซลล์เดียว แต่จะจัดการกับมันอย่างไร? จริงๆแล้วมีหลายวิธีที่ยุ่งยากในการช่วยให้เราปรับขนาดรูปภาพให้พอดีกับขนาดของเซลล์ได้อย่างรวดเร็ว

ปรับขนาดรูปภาพที่เลือกให้พอดีกับเซลล์เดียวด้วย VB Macro

ปรับขนาดรูปภาพที่แทรกให้พอดีกับเซลล์ด้วย Kutools for Excel


ลูกศรสีฟ้าฟองขวา ปรับขนาดรูปภาพที่เลือกให้พอดีกับเซลล์เดียวด้วย VB Macro

เราสามารถใช้มาโคร VB เพื่อปรับขนาดรูปภาพที่เลือกให้พอดีกับเซลล์เดียว แต่ไม่สามารถปรับขนาดความกว้างและความสูงของรูปภาพด้วยตนเองได้ คุณสามารถทำได้โดยทำตามขั้นตอนต่อไปนี้:

ขั้นตอนที่ 1: แทรกรูปภาพลงในแผ่นงานและเลือกรูปภาพที่คุณจะปรับขนาดให้พอดีกับเซลล์เดียว

doc-ปรับขนาดรูปภาพให้พอดีกับเซลล์1

ขั้นตอนที่ 2: กดปุ่มค้างไว้ ALT + F11 และจะเปิดไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

ขั้นตอนที่ 3: คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางมาโครต่อไปนี้ในหน้าต่างโมดูล

VBA: ปรับขนาดรูปภาพที่เลือกให้พอดีกับเซลล์

Public Sub FitPic()
On Error GoTo NOT_SHAPE
Dim PicWtoHRatio As Single
Dim CellWtoHRatio As Single
With Selection
PicWtoHRatio = .Width / .Height
End With
With Selection.TopLeftCell
CellWtoHRatio = .Width / .RowHeight
End With
Select Case PicWtoHRatio / CellWtoHRatio
Case Is > 1
With Selection
.Width = .TopLeftCell.Width
.Height = .Width / PicWtoHRatio
End With
Case Else
With Selection
.Height = .TopLeftCell.RowHeight
.Width = .Height * PicWtoHRatio
End With
End Select
With Selection
.Top = .TopLeftCell.Top
.Left = .TopLeftCell.Left
End With
Exit Sub
NOT_SHAPE:
MsgBox "Select a picture before running this macro."
End Sub

ขั้นตอนที่ 4: กดปุ่ม F5 กุญแจสำคัญในการเรียกใช้แมโครนี้

ขั้นตอนที่ 5: ทำซ้ำขั้นตอนด้านบนเพื่อปรับขนาดรูปภาพอื่น ๆ ให้พอดีกับเซลล์เดียว

ตอนนี้รูปภาพที่แทรกทั้งหมดจะถูกปรับขนาดและพอดีกับเซลล์ ดูภาพหน้าจอต่อไปนี้:

doc-ปรับขนาดรูปภาพให้พอดีกับเซลล์2

หมายเหตุ: คุณสามารถปรับขนาดภาพได้เพียงครั้งเดียว หากคุณเลือกมากกว่าหนึ่งภาพในครั้งเดียวกล่องโต้ตอบคำเตือนจะปรากฏขึ้น


ลูกศรสีฟ้าฟองขวา ปรับขนาดรูปภาพที่แทรกให้พอดีกับเซลล์ด้วย Kutools for Excel

ถ้าคุณมี Kutools สำหรับ Excel ติดตั้งแล้วคุณสามารถใช้ไฟล์ นำเข้ารูปภาพ เครื่องมือในการปรับขนาดรูปภาพทั้งหมดให้พอดีกับเซลล์หรือมีความสูงคงที่ระหว่างการแทรกรูปภาพ

Kutools สำหรับ Excel มีเครื่องมือ Excel ที่มีประโยชน์มากกว่า 300 รายการ ทดลองใช้ฟรีโดยไม่มีข้อ จำกัด ใน 30 วัน Get it Now.

ขั้นตอนที่ 1: เลือกเซลล์ช่วงที่คุณต้องการแทรกรูปภาพแล้วคลิกไฟล์ Enterprise >นำเข้า / ส่งออก > นำเข้ารูปภาพ. ดูภาพหน้าจอต่อไปนี้:

doc-ปรับขนาดรูปภาพให้พอดีกับเซลล์-1

ขั้นตอนที่ 2: ในไฟล์ นำเข้ารูปภาพ กล่องโต้ตอบเลือกลำดับการแทรกในรายการดรอปดาวน์แล้วคลิก เพิ่ม เพื่อเพิ่มรูปภาพที่คุณต้องการจากไฟล์หรือโฟลเดอร์จากนั้นคลิก ขนาด ปุ่ม. ดูภาพหน้าจอ:

doc-ปรับขนาดรูปภาพให้พอดีกับเซลล์-2

ขั้นตอนที่ 3: ตรวจสอบ จับคู่ขนาดเซลล์ ตัวเลือก จากนั้นคลิก Ok > นำเข้า เพื่อปิดกล่องโต้ตอบ ดูภาพหน้าจอ:

doc-ปรับขนาดรูปภาพให้พอดีกับเซลล์-3

ตอนนี้คุณสามารถเห็นรูปภาพที่แทรกให้พอดีกับเซลล์

doc-ปรับขนาดรูปภาพให้พอดีกับเซลล์-4

หมายเหตุ: คุณยังสามารถระบุความสูงและความกว้างของเซลล์ในขั้นตอนที่ 3 เพื่อปรับขนาดรูปภาพ

หากคุณต้องการทราบข้อมูลเพิ่มเติมเกี่ยวกับเรื่องนี้ นำเข้ารูปภาพ โปรดเยี่ยมชม โปรดคลิกที่นี่เพื่ออ่านรายละเอียดเพิ่มเติม.


บทความที่เกี่ยวข้อง:

วิธีปรับขนาดเซลล์หลายเซลล์ให้พอดีกับรูปภาพด้านบนอย่างรวดเร็วใน Excel

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
  • เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
  • เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!
Comments (15)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
La macro posiziona l'immagine "Immagine 2" al centro della cella ("D5"), anche se questa è unita ad altre celle. Spero possa esservi utile

Sub ImpFoto()
Dim hcell As Single ' altezza cella
Dim Lcell As Single ' larghezza cella
Dim hfoto As Single ' altezza foto
Dim Lfoto As Single ' larghezza foto
Dim Rfoto As Single ' rapporto foto h/L

Range("D5").Select

hcell = Selection.Height
Lcell = Selection.Width
hfoto = ActiveSheet.Shapes("Immagine 2").Height
Lfoto = ActiveSheet.Shapes("Immagine 2").Width
Rfoto = hfoto / Lfoto

If hfoto < Lfoto Then
Lfoto = Lcell - 10
hfoto = Lfoto * Rfoto

If hfoto > hcell Then
hfoto = hcell - 3
Lfoto = hfoto / Rfoto
End If

ActiveSheet.Shapes("Immagine 2").Height = hfoto
ActiveSheet.Shapes("Immagine 2").Width = Lfoto
Else
hfoto = hcell - 10
Lfoto = hfoto / Rfoto
ActiveSheet.Shapes("Immagine 2").Height = hfoto
ActiveSheet.Shapes("Immagine 2").Width = Lfoto
End If

Range("D5").Select

With ActiveSheet.Shapes("Immagine 2")
.Top = Selection.Top + (Selection.Height - .Height) / 2
.Left = Selection.Left + (Selection.Width - .Width) / 2
End With
End Sub
This comment was minimized by the moderator on the site
Thank you, it really works!
This comment was minimized by the moderator on the site
Hi, Need this code disabling the lock aspect ratio
This comment was minimized by the moderator on the site
Hi..
perfact solution. But i want that function to work with command button. i need to make a command button to insert and auto resize to cell size. please help.
This comment was minimized by the moderator on the site
Brilliant! Works great! Just what I was looking for! Thank you!
This comment was minimized by the moderator on the site
it works if the cells are not merged. unfortunately, I merged some cells and it fits only in the upper left cell which makes the photo very tiny.
This comment was minimized by the moderator on the site
Hi, I really love this macro that makes images fit cells, it really helped me with some work stuff. But does anyone know how to write this code for applescript? I have to use macs and the apple version of excel, Numbers, only uses applescript. Help! Many thanks, Harry
This comment was minimized by the moderator on the site
Thanks it did work but I have about 500 pictures so I don't want to do them one at a time - how do I do them all at the same time please?
This comment was minimized by the moderator on the site
Works!! But i have one question, i want to fit a img in a range of cells merged, how can i do it?
This comment was minimized by the moderator on the site
Public Sub FitPic()
'https://www.extendoffice.com/documents/excel/1060-excel-resize-picture-to-fit-cell.html
'Slight modification to resize into merged cells
On Error GoTo NOT_SHAPE
Dim PicWtoHRatio As Single
Dim CellWtoHRatio As Single
With Selection
PicWtoHRatio = .Width / .Height
End With
With Selection.TopLeftCell
CellWtoHRatio = .MergeArea.Width / .MergeArea.Height
End With
Select Case PicWtoHRatio / CellWtoHRatio
Case Is > 1
With Selection
.Width = .TopLeftCell.MergeArea.Width
.Height = .Width / PicWtoHRatio
End With
Case Else
With Selection
.Height = .TopLeftCell.MergeArea.Height
.Width = .Height * PicWtoHRatio
End With
End Select
With Selection
.Top = .TopLeftCell.MergeArea.Top
.Left = .TopLeftCell.MergeArea.Left
.Placement = xlMoveAndSize
End With
Exit Sub
NOT_SHAPE:
MsgBox "Select a picture before running this macro."
End Sub
This comment was minimized by the moderator on the site
[quote]Works!! But i have one question, i want to fit a img in a range of cells merged, how can i do it?By Marcelo[/quote] Marcelo did you get the updated marco for the merged cell? I am trying to do the same thing. thanks
This comment was minimized by the moderator on the site
I tried this macro last night and it adjust only the height. The width it doesn't incorrectly. Any Help please?
This comment was minimized by the moderator on the site
Thank you this was perfect!!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations