Picture number

B

Bobby

How can I know the picture number in a specific cell? I would like to
pass the info to the
ActiveSheet.Shapes("Picture xx").Select
Thank's ahead
 
D

Dave Peterson

The pictures actually float over the cells. But you could use something like:

Dim myCell as range
dim myPict as picture
dim FoundIt as boolean

with activesheet
set mycell = .range("c9") 'or something
for each myPict in .pictures
if mypict.topleftcell.address = mycell.address then
foundit = true
exit for
end if
next mypict
end with

if foundit = true then
mypict.select
else
msgbox "No pictures found!"
end if
 
B

Bobby

Thank's Dave,
When I try the macro I get a mismatch error on

For Each myPict In .Pictures
Any clue?
Thank's ahead
 
D

Dave Peterson

Did you change other stuff in the code?

Do you still have this line:
dim myPict as Picture
 
D

Dave Peterson

Post your code. I don't see anything that jumps out. (It worked ok for me,
too.)
Dave I did not change anything and yes I still have
dim myPict as Picture
 
B

Bobby

OK this is it:
At the time that I run this macro the cell cursor has a picture in it
at Range("D12")
Sub Macro4()
'
' Macro4 Macro
'
Dim myCell As Range
Dim myPict As Picture
Dim FoundIt As Boolean


With ActiveSheet
Set myCell = .Range("D12") 'or something
For Each myPict In .Pictures
If myPict.TopLeftCell.Address = myCell.Address Then
FoundIt = True
Exit For
End If
Next myPict
End With


If FoundIt = True Then
myPict.Select
Else
MsgBox "No pictures found!"
End If

End Sub
 
D

Dave Peterson

I still don't get a mismatch error when I try the code.
OK this is it:
At the time that I run this macro the cell cursor has a picture in it
at Range("D12")
Sub Macro4()
'
' Macro4 Macro
'
Dim myCell As Range
Dim myPict As Picture
Dim FoundIt As Boolean

With ActiveSheet
Set myCell = .Range("D12") 'or something
For Each myPict In .Pictures
If myPict.TopLeftCell.Address = myCell.Address Then
FoundIt = True
Exit For
End If
Next myPict
End With

If FoundIt = True Then
myPict.Select
Else
MsgBox "No pictures found!"
End If

End Sub
 
D

Dave Peterson

I don't have a guess why it's not working for you--do you have other shapes in
that activesheet that might confuse excel?

Maybe going through the shapes collection would work better:

Option Explicit

Sub Macro4()
'
' Macro4 Macro
'
Dim myCell As Range
Dim myShape As Shape
Dim FoundIt As Boolean


With ActiveSheet
Set myCell = .Range("D12") 'or something
For Each myShape In .Shapes
If myShape.TopLeftCell.Address = myCell.Address Then
FoundIt = True
Exit For
End If
Next myShape
End With


If FoundIt = True Then
myShape.Select
Else
MsgBox "No pictures found!"
End If

End Sub

OK this is it:
At the time that I run this macro the cell cursor has a picture in it
at Range("D12")
Sub Macro4()
'
' Macro4 Macro
'
Dim myCell As Range
Dim myPict As Picture
Dim FoundIt As Boolean

With ActiveSheet
Set myCell = .Range("D12") 'or something
For Each myPict In .Pictures
If myPict.TopLeftCell.Address = myCell.Address Then
FoundIt = True
Exit For
End If
Next myPict
End With

If FoundIt = True Then
myPict.Select
Else
MsgBox "No pictures found!"
End If

End Sub
 
Top