how do I insert a picture using a formula?
H AJ,
One way would be...
Paste the 45 pictures onto sheet 1, select them all then run this macro
to rename them systematically Pic1, Pic2 etc...
Public Sub ReNamePics()
Dim Pic As Shape, K As Long
For Each Pic In Selection.ShapeRange
Pic.Name = Pic.Name & Pic.Name
Next Pic
For Each Pic In Selection.ShapeRange
K = K + 1
Pic.Name = "Pic" & K
Next Pic
End Sub
Type the formula =RAND() into B1 then fill it across to AT1 for the 45
random numbers.
Type 1 into B2 and 2 into C2. Select B2:C2 then fill across to AT2 to
give the numbers 1 to 45 in B2:AT2
Make columns A to K wide enough so that they are able to accommodate
the biggest of the 45 pictures.
Control the visibility of the pictures using the following macro, which
would be best run by assigning it to a Button from the Forms Toolbar.
Sub ShowPics()
'Jumble row 1 (1 to 45)
Range("B1:AT2").Sort Key1:=Range("B1"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
Dim rngCell As Range
Dim Pic As Shape
'Hide all Pics
For Each Pic In ActiveSheet.Shapes
'Shape Type of a Picture is 13. If characters
'are not Pictures, eg AutoShapes, then
'code line below will need adjusting
If Pic.Type = 13 Then Pic.Visible = False
Next Pic
'Show Cell's B2:K2 Pic in row 3
For Each rngCell In Range("B3:K3")
With ActiveSheet.Shapes("Pic" & _
rngCell.Offset(-1, 0).Value)
.Visible = True
.Top = rngCell.Top
.Left = rngCell.Left
End With
Next rngCell
End Sub
If you are typing your answer and you want it checked, then you could
use a VLOOKUP formula and a table (either hidden or on another sheet)
with Picture number in the first column and correct answer in the
second column
Ken Johnson
|