+ Reply to Thread
Results 1 to 8 of 8

if image is present, adjust autoshape

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    if image is present, adjust autoshape

    Hi there.

    question from a noob please. How can i let excel check if there is a picture in in a cell of a range in column A, and if yes, select the autoshape in the row cell but column B on sheet2, and adjust its interior color to white?

    Would appreciate if someone could advise me some code
    thanks,
    A2k

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: if image is present, adjust autoshape

    You still need to be using the TopLeftCell property in order to determine a shapes position relative to the worksheet.

    Maybe things would be clearer if you posted small example file
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: if image is present, adjust autoshape

    here a quick example. the macro should check if there is a picture in column B on sheet "Picture", and if yes, adjust the shape in the same row but column L on sheet "VIP" to white.

    thanks!
    A2k
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: if image is present, adjust autoshape

    no ideas anyone?

  5. #5
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: if image is present, adjust autoshape

    try this

    Sub testy()
    
        Dim pic As Shape, star As Shape
        
        'make all stars on "VIP" white
        For Each star In Sheet1.Shapes
        
            If star.TopLeftCell.Column = 10 Then star.Fill.ForeColor.SchemeColor = 9
            
        Next star
                    
        'look for pics in col B of "Picture" and change
        'corresponding star on same row of "VIP" to yellow
        For Each pic In Sheet2.Shapes
        
            If pic.Type = msoPicture And pic.TopLeftCell.Column = 2 Then
            
                For Each star In Sheet1.Shapes
                
                    With star
                    
                        If .TopLeftCell.Row = pic.TopLeftCell.Row And .TopLeftCell.Column = 10 _
                             Then .Fill.ForeColor.SchemeColor = 13
                        
                    End With
                    
                Next star
                
            End If
        
        Next pic
    
    End Sub
    Last edited by blackworx; 09-05-2009 at 06:17 AM.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: if image is present, adjust autoshape

    This takes a different approach using webdings2 font rather than images.

    The user defined function returns true or false if the picture is there on sheet picture.

    Public Function UDF_HASPICTURE(SheetName As String, CellAddress As String) As Boolean
        
        Dim shtTemp As Worksheet
        Dim rngCheck As Range
        Dim shpTemp As Shape
        
        On Error GoTo ErrHasPicture
        
        If Len(SheetName) = 0 Then
            ' use active sheet
            Set shtTemp = ActiveSheet
        Else
            Set shtTemp = Worksheets(SheetName)
        End If
        
        Set rngCheck = shtTemp.Range(CellAddress)
        
        If Not shtTemp Is Nothing Then
            For Each shpTemp In shtTemp.Shapes
                If Not Intersect(shpTemp.TopLeftCell, rngCheck) Is Nothing Then
                    UDF_HASPICTURE = True
                    Exit For
                End If
            Next
        End If
        
    ErrHasPicture:
        Exit Function
        
    End Function
    The formula would be

    =IF(UDF_HASPICTURE("Picture","B" & ROW()),"é","")
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: if image is present, adjust autoshape

    @ blackworks

    thank you very much for this, after making some minor adjustments to your code, it works flawlessly now. This helps me to finalize a project I was torturing myself with for quite a while already. thanks a lot!

    thanks to all the other contributors as well,
    A2k

  8. #8
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: if image is present, adjust autoshape

    You're welcome A2k, although Andy's solution is more robust imo. My code is a quick and dirty fix, depends on a lot of assumptions and is therefore quite "brittle". Good luck with the rest of your project

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1