In Excel, I will enter a part # for a piece of hardware in a cell
(such as "XDA-F" or "XAD" or "XMF").
Based on the part number entered, I want Excel to paste a front panel
image for that device in another cell so many columns away from the
part # cell.
I can find no way to do this. |
Request for Question Clarification by
maniac-ga
on
29 Mar 2004 17:25 PST
Hello Morganm,
It appears you have posted this question twice. See
http://answers.google.com/answers/threadview?id=321992
for the other copy. I sugest you close the second question to prevent
getting charged twice.
Where are you getting the "front panel image" to paste,
- from the clipboard,
- from a file (e.g., XDA-F.gif, XAD.gif, XMF.gif, ...)
- from some other source (e.g., Insert -> Picture -> (one of the options listed)
A macro should be able to handle this type of action - as a button,
form entry, or similar action. If you want this to be an automatic
action based on the user entering the value in a field in a form, I
should be able to set it up as a validation function (both validate
and do the display update).
Let me know if this sounds like what you are asking for. If not,
please explain the problem in a little more detail.
--Maniac
|
Clarification of Question by
morganm-ga
on
29 Mar 2004 18:04 PST
The image to be pasted will come from a file (Insert -> Picture ->
(one of the options listed).
It should be automatic. For example, if in the part number column row
2 one enters "1" or "2" or "3", then in column (as an example) J
pitcure file 1, 2 or 3 would be pasted.
Similar for other rows.
Similar for other co;umns (e.g., a part # entered in B2 would result
in the correct file being pasted in K2.
|
Request for Question Clarification by
maniac-ga
on
29 Mar 2004 19:37 PST
Hello Morganm,
The basic steps can be done with the macro listed at the end. This is
a simple example that will insert the file specified and align it to
the top / left of cell J2. Note - this does not put it "into J2", just
aligned to the same location. That appears to be what you asked for -
but please confirm.
To test the macro, do the following steps:
[1] open Excel w/ a sample spreadsheet (workbook)
[2] Tools -> Macro -> Visual Basic Editor
this will bring up the Visual Basic Editor, generally with some
windows on the left.
[3] Insert -> Module
this should open a window with the name of the workbook - Module1 (code).
[4] Copy / paste the macro into this new code window. Change the file
name to a file you have on your system.
[5] Excel -> Close and return to Microsoft Excel
[6] Tools -> Macro -> Macros
to bring up a dialog box, selectc the InsertPict macro and then click on Run.
The image file you selected in step 4 should be inserted and aligned with cell J2.
If this does what you want - I can suggest some methods of
automatically reading the value of a cell - say when a button is
pressed or when the field is filled in (in a form).
If not, please explain in some more detail the effect you are trying to achieve.
--Maniac
Sub InsertPict()
'
' InsertPict Macro
' Macro recorded 3/29/2004 by Maniac
'
'
ActiveSheet.Pictures.Insert("Name-of-file-goes-here").Select
Selection.ShapeRange.Left = Columns("j").Left
Selection.ShapeRange.Top = Rows("2").Top
End Sub
|
Clarification of Question by
morganm-ga
on
29 Mar 2004 22:27 PST
Yes, the macro you offered pasted the specified file. What I need is a
bit more invovled.
There will be something like 40 picture files.
In the first say 20 columns of the sheet I will be entering these
names individually in cells on row 1, 10, and say 20.
When I enter say XAD-F in cell A1, I want it to past the image file
named XAD-F at cell T2. If I then enter XAD-F in cell A2, I want it
to paste the image file named XAD-F at cell S2. If I change my minde,
erase cell A2 and enter XER-X, then I want it to erase the image
pasted at S2 and replace it with the image file named XER-X.
Etc.
As to pasting 'at' vs 'in' the cell, could you offer examples of how
to do it either way so I can see what works best for me.
Thanks!
|
Request for Question Clarification by
maniac-ga
on
30 Mar 2004 18:46 PST
Hello Morganm,
The number of image files should not be a problem - as long as the
names match the phrases you are entering, the macro can pick it up.
Revise the macro to read:
S$ = ActiveCell.Address
ActiveSheet.Pictures.Insert(ActiveCell.Value).Select
Selection.ShapeRange.Left = Columns("j").Left
Selection.ShapeRange.Top = Rows("2").Top
Selection.ShapeRange.Name = S$
and the macro will read the filename from the "active cell" to insert
the picture and set its name to the address of the "active cell".
After running this macro, bring up the immediate window in Visual
Basic and enter
print selection.name
$B$1 [this will vary by active cell]
print activesheet.shapes("$B$1").top [replace $B$1 with the
previous value printed]
13
to get the top of the row (in my case - the top of row 2 and the top of the image).
So
- we have a method to look up the image based on the name entered in a cell
- we have a method to name the image / so we can delete it later based on that name
- we can run a macro from clicking a button [I can show that if that is acceptable]
I don't see any specific way to run the macro when the user enters a
value on the worksheet. I thought validation formulas would do the
job, but it appears they only refer to Excel functions, not macros.
Also Assign Macro is not available as a pop up menu item with cells
(you can assign macros to images, buttons, etc.).
I still do not understand the relationship between the source (data
entry) cells and the destination (image pasting) cells. Can you
explain that more fully.
Also, to repeat, there does not seem to be a way to put an image
"into" a cell. Just to put it at the proper location, covering it. You
asked to put the image "in another cell"; I can make it look like that
(proper location) but not actually put the image into the cell (to set
its value). If that is OK - please indicate that.
So - I can produce a macro that scans a set of cells. Within each of
those cells - it will use the value to find an image file of the same
name and paste it into a specific location on the worksheet (removing
any previous image). The location of the image will vary by some
relationship you describe.
Is this what you are asking for?
--Maniac
|
Clarification of Question by
morganm-ga
on
30 Mar 2004 20:00 PST
Hi, Maniac-ga
I think your last paragraph is the solution.
Here is what I am doing.
I am configuring a signal routing system to specific customer needs.
Each of 21 slots in each row of a frame can have one of several cards
mounted in it depending on customer needs. In addition to entering
the name of teh card (e.g. XAD-F) is use other cells below that to
enter wiring data, etc.
Then in another part of the spreadsheet I want to create a front panel
layout suing pdf drawings of the actual front panels of the modules.
What I had wanted to have happen was that as I enter the name (e.g.
XAD-F), Excel would automatically paste in the appropriate licture of
the front panel.
I have been trying to get this to happen for over a year, had given
up, and then saw the Google Question site.
The sloution you offer in your last paragraph will be sufficient for
most cases. I think I will try it out for awhile.
Now I need to figure out how to get this system to pay you.
Thanks for the help!
|