Loncat ke daftar isi utama

Bagaimana cara mengubah ukuran gambar agar sesuai dengan sel di Excel?

Biasanya gambar yang disisipkan mengapung di atas sel, dan seringkali satu gambar menutupi banyak sel. Jika lembar kerja memiliki banyak gambar, Anda mungkin ingin meletakkan setiap gambar ke dalam satu sel. Tapi bagaimana cara menghadapinya? Sebenarnya, ada beberapa cara rumit untuk membantu kami mengubah ukuran gambar agar sesuai dengan ukuran sel dengan cepat.

Ubah ukuran gambar yang dipilih agar pas dengan satu sel dengan VB Macro

Ubah ukuran gambar yang disisipkan agar sesuai dengan sel dengan Kutools for Excel


panah gelembung kanan biru Ubah ukuran gambar yang dipilih agar pas dengan satu sel dengan VB Macro

Kita bisa menerapkan makro VB untuk mengubah ukuran gambar yang dipilih agar pas dengan satu sel, tetapi tidak secara manual mengubah ukuran lebar dan tinggi gambar. Anda dapat melakukannya dengan langkah-langkah berikut:

Langkah 1: Sisipkan gambar ke dalam lembar kerja, dan pilih gambar yang akan Anda ubah ukurannya agar pas dengan satu sel.

doc-resize-gambar-untuk-sesuai-sel1

Langkah 2: Tahan ALT + F11 kunci, dan itu membuka Microsoft Visual Basic untuk Aplikasi jendela.

Langkah 3: Klik Menyisipkan > Modul, dan tempelkan makro berikut di Jendela Modul.

VBA: Ubah ukuran gambar yang dipilih agar pas dengan sel.

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

Langkah 4: Tekan F5 kunci untuk menjalankan makro ini.

Langkah 5: Ulangi langkah-langkah di atas untuk mengubah ukuran gambar lain agar pas dengan satu sel.

Sekarang semua gambar yang disisipkan diubah ukurannya dan pas dengan sel. Lihat screenshot berikut:

doc-resize-gambar-untuk-sesuai-sel2

Note: Anda hanya dapat mengubah ukuran satu gambar satu kali. Jika Anda memilih lebih dari satu gambar satu kali, kotak dialog peringatan akan muncul.


panah gelembung kanan biru Ubah ukuran gambar yang disisipkan agar sesuai dengan sel dengan Kutools for Excel

Jika Anda memiliki Kutools untuk Excel diinstal, Anda dapat menerapkannya Impor Gambar alat untuk mengubah ukuran semua gambar agar sesuai dengan sel atau dengan ketinggian tetap selama memasukkan gambar.

Kutools untuk Excel mencakup lebih dari 300 alat Excel yang praktis. Gratis untuk mencoba tanpa batasan dalam 30 hari. Dapatkan Sekarang.

Langkah 1: Pilih sel rentang yang ingin Anda sisipkan gambar dan klik Enterprise >Impor / Ekspor > Impor Gambar. Lihat screenshot berikut:

doc-resize-gambar-agar-sesuai-sel-1

Langkah 2: Di Impor Gambar kotak dialog, pilih urutan penyisipan dalam daftar drop-down, dan klik Add tombol untuk menambahkan gambar yang Anda butuhkan dari file atau folder, lalu klik Ukuran tombol. Lihat tangkapan layar:

doc-resize-gambar-agar-sesuai-sel-2

Langkah 3: Periksa Ukuran sel yang cocok pilihan. Lalu klik Ok > impor untuk menutup dialog. Lihat tangkapan layar:

doc-resize-gambar-agar-sesuai-sel-3

Sekarang Anda dapat melihat gambar-gambar yang disisipkan agar pas dengan sel.

doc-resize-gambar-agar-sesuai-sel-4

Note: Anda juga bisa menentukan tinggi dan lebar sel di langkah 3 untuk mengubah ukuran gambar.

Jika Anda ingin tahu lebih banyak tentang ini Impor Gambar fitur, silakan kunjungi di sini.


Artikel terkait:

Bagaimana mengubah ukuran banyak sel agar sesuai dengan gambar di atasnya dengan cepat di Excel?

Alat Produktivitas Kantor Terbaik

馃 Kutools AI Ajudan: Merevolusi analisis data berdasarkan: Eksekusi Cerdas   |  Hasilkan Kode  |  Buat Rumus Khusus  |  Analisis Data dan Hasilkan Grafik  |  Aktifkan Fungsi Kutools...
Fitur Populer: Temukan, Sorot, atau Identifikasi Duplikat   |  Hapus Baris Kosong   |  Gabungkan Kolom atau Sel tanpa Kehilangan Data   |   Putaran tanpa Formula ...
Pencarian Super: VLookup Beberapa Kriteria    VLookup Nilai Berganda  |   VLookup di Beberapa Lembar   |   Pencarian Fuzzy ....
Daftar Drop-down Lanjutan: Buat Daftar Drop Down dengan Cepat   |  Daftar Drop Down yang Bergantung   |  Multi-pilih Drop Down List ....
Manajer Kolom: Tambahkan Jumlah Kolom Tertentu  |  Pindahkan Kolom  |  Alihkan Status Visibilitas Kolom Tersembunyi  |  Bandingkan Rentang & Kolom ...
Fitur Unggulan: Fokus Kisi   |  Tampilan Desain   |   Bar Formula Besar    Manajer Buku Kerja & Lembar   |  Perpustakaan Sumberdaya (Teks otomatis)   |  Pemetik tanggal   |  Gabungkan Lembar Kerja   |  Enkripsi/Dekripsi Sel    Kirim Email berdasarkan Daftar   |  Filter Super   |   Filter Khusus (filter tebal/miring/coret...) ...
15 Perangkat Teratas12 Teks Tools (Tambahkan Teks, Hapus Karakter, ...)   |   50 + Grafik jenis (Gantt Chart, ...)   |   40+ Praktis Rumus (Hitung usia berdasarkan ulang tahun, ...)   |   19 Insersi Tools (Masukkan Kode QR, Sisipkan Gambar dari Jalur, ...)   |   12 Konversi Tools (Angka ke Kata, Konversi Mata Uang, ...)   |   7 Gabungkan & Pisahkan Tools (Lanjutan Gabungkan Baris, Pisahkan Sel, ...)   |   ... dan banyak lagi

Tingkatkan Keterampilan Excel Anda dengan Kutools for Excel, dan Rasakan Efisiensi yang Belum Pernah Ada Sebelumnya. Kutools for Excel Menawarkan Lebih dari 300 Fitur Lanjutan untuk Meningkatkan Produktivitas dan Menghemat Waktu.  Klik Di Sini untuk Mendapatkan Fitur yang Paling Anda Butuhkan...

Deskripsi Produk


Tab Office Membawa antarmuka Tab ke Office, dan Membuat Pekerjaan Anda Jauh Lebih Mudah

  • Aktifkan pengeditan dan pembacaan tab di Word, Excel, PowerPoint, Publisher, Access, Visio, dan Project.
  • Buka dan buat banyak dokumen di tab baru di jendela yang sama, bukan di jendela baru.
  • Meningkatkan produktivitas Anda sebesar 50%, dan mengurangi ratusan klik mouse untuk Anda setiap hari!
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