How do I convert a picture's .Width to .Column.Width so I can embed it into a cell whose .ColumnWidth must be set?

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
833
Office Version
  1. 365
Platform
  1. Windows
I did research this but cannot figure it out.

I am trying to embed a picture into a cell. My problem is that I need to convert the picture's .Width to the .ColumnWidth for the cell into which the picture will be embedded, so the cell is wide enough. How do I do the conversion?

I have researched this but the best I could find is the following sub that converts a CELL's .Width to .ColumnWidth.

Source: What is the unit of Excel column width? - Simple Excel VBA

VBA Code:
Sub f_width(rng As Range, i As Long)

Dim j As Long

With rng
    For j = 1 To 3
        .ColumnWidth = i / .Width * .ColumnWidth
    Next j
End With

End Sub

The logic works well to convert a CELL's .Width to .ColumnWidth. But I need to convert the PICTURE's .Width to .ColumnWidth for the cell into which the picture is embedded.

I hope that a math plus Excel wizard can tell me how to do this.
 
That should have read 5.35 as a starter.
Sorry for the confusion.
 
Upvote 0
Solution

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
BTW, I seldom use copy anymore. I use following.
Code:
Sheets("Sheet2").Shapes("Picture 2").Duplicate.Cut
Sheets("Sheet3").Range("A5").PasteSpecial xlPasteAll
 
Upvote 0
I was intrigued enough by your suggestion that I tried it. But I had an issue. After the paste the result (Selection) is a range not a picture. My code needs a picture (object) to work with.

VBA Code:
'   Copy the original picture (Shape) to the wsToSheet worksheet.
    oPicture.Duplicate.Cut
    prToCell.PasteSpecial xlPasteAll

'   This reports that the resulting object is a range...
   Debug.Print TypeName(Selection)

'   ...so this code fails. The pasted picture becomes the Selection.
    Set oPicture2 = Selection
 
Upvote 0
Code:
Sub Jim_From_Oakland()
    Sheets("Sheet2").Shapes("Picture 2").Duplicate.Cut
    Sheets("Sheet3").Range("J4").PasteSpecial xlPasteAll
With Sheets("Sheet3")
    .Pictures(Worksheets("Sheet3").Pictures.Count).Name = "OaklandJim"
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,106
Messages
6,123,124
Members
449,097
Latest member
mlckr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top