メインコンテンツへスキップ

Excelのセルに合うように画像のサイズを変更するにはどうすればよいですか?

通常、挿入された画像はセルの上に浮かんでおり、ほとんどの場合、XNUMXつの画像が多くのセルをカバーしています。 ワークシートに多数の画像がある場合は、各画像をXNUMXつのセルに配置することをお勧めします。 しかし、どのように対処するのですか? 実際、セルのサイズにすばやく合うように画像のサイズを変更するには、いくつかの注意が必要な方法があります。

選択した画像のサイズを変更して、VBマクロを使用して単一のセルに合わせます

挿入された画像のサイズを変更して、Kutools forExcelを使用してセルに合わせます


矢印青い右バブル 選択した画像のサイズを変更して、VBマクロを使用して単一のセルに合わせます

VBマクロを適用して、選択した画像のサイズをXNUMXつのセルに合わせて変更できますが、画像の幅と高さを手動で変更することはできません。 次の手順で実行できます。

ステップ1:画像をワークシートに挿入し、XNUMXつのセルに合うようにサイズを変更する画像を選択します。

doc-resize-pictures-to-fit-cells1

ステップ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:上記の手順を繰り返して、他の画像のサイズをXNUMXつのセルに合わせて変更します。

これで、挿入されたすべての画像のサイズが変更され、セルに収まります。 次のスクリーンショットを参照してください。

doc-resize-pictures-to-fit-cells2

Note:一度にサイズ変更できる画像はXNUMXつだけです。 複数の画像を一度に選択すると、警告ダイアログボックスが表示されます。


矢印青い右バブル 挿入された画像のサイズを変更して、Kutools forExcelを使用してセルに合わせます

あなたが持っている場合 Kutools for Excel インストールすると、適用できます 写真をインポートする セルに合わせて、または画像の挿入時に高さを固定して、すべての画像のサイズを変更するツール。

Kutools for Excel 300以上の便利なExcelツールが含まれています。 30日以内に制限なしで無料でお試しいただけます。 今すぐ入手.

ステップ1:画像を挿入する範囲セルを選択し、 Enterprise >輸出入 > 写真をインポートする。 次のスクリーンショットを参照してください。

doc-resize-picture-to-fit-cell-1

ステップ2: 写真をインポートする ダイアログボックスで、ドロップダウンリストから挿入順序を選択し、をクリックします Add ボタンをクリックしてファイルまたはフォルダから必要な画像を追加し、をクリックします サイズ ボタン。 スクリーンショットを参照してください:

doc-resize-picture-to-fit-cell-2

ステップ3:チェック 一致するセルサイズ オプション。 次に、をクリックします Ok > インポート ダイアログを閉じます。 スクリーンショットを参照してください:

doc-resize-picture-to-fit-cell-3

これで、セルに合わせて画像が挿入されていることがわかります。

doc-resize-picture-to-fit-cell-4

Note:手順3でセルの高さと幅を指定して、画像のサイズを変更することもできます。

これについてもっと知りたい場合 画像のインポート 機能、訪問してください ここ.


関連記事:

Excelで複数のセルのサイズを変更して、その上の画像にすばやく合わせるにはどうすればよいですか?

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、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