Run-time error 1004: Application-defined or object-defined error?

Pecco75

New Member
Joined
Apr 12, 2013
Messages
4
Hello,
the idea is to center an image in the middle of a cell where the cell's size is variable. This shall be done for a column of images if a certain cell in the same row contains content different from 0. If not the image shall be invisible.
Can you please help me to identify the problem here:

Sub Center()
Dim Position As Integer
Dim Picture As Integer
Picture = 6
For Position = 7 To 320​
If Sheets("List of Measures").Cells(Position, 2).Value = "" Then​
Sheets("List of Measures").Shapes(Picture).Visible = msoFalse​
Else​
Call CenterMe(Sheets("List of Measures").Shapes(Picture), Sheets("List of Measures").Range(Cells(Position, 9)))​
Picture = Picture + 1
End If​
Next Position​
End Sub


Private Sub CenterMe(Shp As shape, OverCells As Range)
With OverCells​
Shp.Left = .Left + ((.Width - Shp.Width) / 2)​
Shp.Top = .Top + ((.Height - Shp.Height) / 2)​
End With​
End Sub



Thank you =)
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi Pecco75,

I have to admit that I am brand new to VBA, so my suggestion is based on very limited knowledge. However, I recently had the same error message, and the answer to my issue was the same as the one I am about to offer - so you never know.

I think that you may need to alter your line:

Code:
If Sheets("List of Measures").Cells(Position, 2).Value = "" Then

To have doubled-up quotation marks - so it would be:

Code:
If Sheets("List of Measures").Cells(Position, 2).Value = [COLOR=#0000cd][B]""""[/B][/COLOR] Then

But like I say, not 100% sure - but might be worth a try!

Good luck,

Andy
 
Upvote 0
Hi Pecco75,

I have to admit that I am brand new to VBA, so my suggestion is based on very limited knowledge. However, I recently had the same error message, and the answer to my issue was the same as the one I am about to offer - so you never know.

I think that you may need to alter your line:

Code:
If Sheets("List of Measures").Cells(Position, 2).Value = "" Then

To have doubled-up quotation marks - so it would be:

Code:
If Sheets("List of Measures").Cells(Position, 2).Value = [COLOR=#0000cd][B]""""[/B][/COLOR] Then

But like I say, not 100% sure - but might be worth a try!

Good luck,

Andy


Thank you for your reply, Andy. Unfortunately I still receive the same error message =/
 
Upvote 0
Code:
Sub Center()
Dim Position As Integer
Dim Picture As Integer
Picture = 2
For Position = 7 To 320
    If Sheets("List of Measures").Cells(Position, 2).Value = "" Then
        Sheets("List of Measures").Shapes(Picture).Visible = msoFalse
    Else
        Call CenterMe(Sheets("List of Measures").Shapes("Picture " & Picture), Sheets("List of Measures").Cells(Position, 9))
        Picture = Picture + 1 ' there is only picture 2
    End If
Next Position

End Sub
 
Private Sub CenterMe(Shp As Shape, OverCells As Range)
     
    With OverCells
        Shp.Left = .Left + ((.Width - Shp.Width) / 2)
        Shp.Top = .Top + ((.Height - Shp.Height) / 2)
    End With
End Sub
 
Last edited:
Upvote 0
Code:
Sub Center()
Dim Position As Integer
Dim Picture As Integer
Picture = 2
For Position = 7 To 320
    If Sheets("List of Measures").Cells(Position, 2).Value = "" Then
        Sheets("List of Measures").Shapes(Picture).Visible = msoFalse
    Else
        Call CenterMe(Sheets("List of Measures").Shapes("Picture " & Picture), Sheets("List of Measures").Cells(Position, 9))
        Picture = Picture + 1 ' there is only picture 2
    End If
Next Position

End Sub
 
Private Sub CenterMe(Shp As Shape, OverCells As Range)
     
    With OverCells
        Shp.Left = .Left + ((.Width - Shp.Width) / 2)
        Shp.Top = .Top + ((.Height - Shp.Height) / 2)
    End With
End Sub

Thank you for your time and help. Unfortunately now the error "Invalid call procedure or argument" occures =/
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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