Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Replace the Text in excel cells with Images

Posted on 2012-09-04
6
Medium Priority
?
451 Views
Last Modified: 2012-09-07
I have a sample attached file which has some 1500 housie tickets.

I would like to replace the numbers with the corresponding image for that number.

I have seperate image files or if required I can copy the images in a cell in excel.  But there is no find and replace command from text to image.

the total numbers will range from 1 to 90 and corresponding 90 images also are ready.
Sample-excel.xlsx
0
Comment
Question by:dilipsjain
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:tdlewis
ID: 38365201
The following function will choose the appropriate shape:
Function selectShape(v) As Shape
Dim found As Boolean
Dim s As Shape
Dim theRow As Variant

    Set selectShape = Nothing
    theRow = Application.VLookup(v, Sheets("Images").Range("A:A"), 1)
    If IsError(theRow) Then Exit Function
    
    found = False
    For Each s In ActiveSheet.Shapes
        If s.TopLeftCell.Row = theRow Then
            found = True
            Exit For
        End If
    Next s
    If found Then Set selectShape = s
End Function

Open in new window

0
 

Author Comment

by:dilipsjain
ID: 38366657
Hi Tdlevis,

Thanks for the comment...

Actually I am very poor at programming etc.  Would it be possible for you to put this function or so live in the excel sheet which I sent to you, so that It becomes possible... What I will do afterwards is copy all the 90 shapes to images sheet with appropriate numbers.

Would it be possible to do the necessary changes in the attached sheet...

It will be a great help to me...
0
 
LVL 10

Accepted Solution

by:
tdlewis earned 1500 total points
ID: 38366725
OK... I added a subroutine to replace the active cell with the corresponding image (if one can be found). The routine also adjusts the cell height and width to match the cell where the image was found.

Note that the file type had to change to xlsm in order to store the macro.
Sub CopyNumberedShape()
Dim theCell As Range
Dim theShape As Shape

    Set theCell = Selection.Cells(1, 1)
    theCell.Select
    Set theShape = selectShape(theCell.Value)
    If Not theShape Is Nothing Then
        theShape.Copy
        If theCell.ColumnWidth < theShape.TopLeftCell.ColumnWidth Then _
            theCell.ColumnWidth = theShape.TopLeftCell.ColumnWidth
        If theCell.RowHeight < theShape.TopLeftCell.RowHeight Then _
            theCell.RowHeight = theShape.TopLeftCell.RowHeight
        theCell.Value = ""
        ActiveSheet.Paste
    End If
End Sub

Open in new window

Sample-excel.xlsm
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dilipsjain
ID: 38367198
Thanks Tdlevis...
This is what I wanted... Just One more request... This is replacing one number at a time.  Is there any way where I could replace all the numbers together or may be looping the macro for all the numbers...

thank you so much :)  

I accept this as my solution.. Just a final help needed.
0
 
LVL 10

Expert Comment

by:tdlewis
ID: 38368351
Writing the code to replace all the numbers is slightly complicated by all the empty cells. Looking at column A implies there are three rows, but looking at column D one would only find two rows. Blank columns make it impossible to select the "Current Region" to get everything. (For example, the "Current Region" for cell A1 is A1:I3.)

Here are some options:
1. Before running the macro, select the cells to be replaced.
2. Name the region where the cells are to be replaced.
3. Hard code the region (currently it's A1:AC3

Are any of these options close to what you had in mind?
0
 

Author Closing Comment

by:dilipsjain
ID: 38377092
Thank u so much....
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question