VBA loop for Each that retrive litte image but not allign

GerryZ

Well-known Member
Joined
Jul 4, 2014
Messages
1,224
Office Version
  1. 365
Platform
  1. Windows
Hello Vba Friends, Im Learning VBA, I' have a code that works fine but only one problem:
I need that in range C2:C16 all images will be allign correctly in the center of the cells
VBA Code:
Option Explicit

Sub InserisciLaFaccina()
Dim cella As Range
Dim Faccina As Shape
For Each Faccina In Foglio1.Shapes
    If Faccina.Name <> "Immagine1" _
        And Faccina.Name <> "Immagine2" _
        And Faccina.Name <> "Immagine3" _
        And Faccina.Name <> "Immagine4" Then
    Faccina.Delete
    End If
Next
    For Each cella In Range("B2:B16")
            If cella.Value < 6 Then
                    Foglio1.Shapes("Immagine3").Copy
                    cella.Offset(0, 1).PasteSpecial
            ElseIf cella.Value >= 6 And cella.Value < 8 Then
                    Foglio1.Shapes("Immagine2").Copy
                    cella.Offset(0, 1).PasteSpecial
             Else
                    Foglio1.Shapes("Immagine1").Copy
                    cella.Offset(0, 1).PasteSpecial
             End If
    Next cella
End Sub

Thank you for your help
 

Attachments

  • hhhhhhhhhhhhhhhhhhhhh.png
    hhhhhhhhhhhhhhhhhhhhh.png
    72.1 KB · Views: 4

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA how can I align the image in the center of the cell?
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Try adding this line after each past special line
VBA Code:
                    Selection.Left = cella.Offset(, 1).Left + cella.Width / 2 - Selection.Width / 2
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,704
Members
449,048
Latest member
81jamesacct

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