ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   inserting graphics in a conditional formatting (https://www.excelbanter.com/excel-programming/430000-re-inserting-graphics-conditional-formatting.html)

Corey ....

inserting graphics in a conditional formatting
 
Untested Codes

Sub SavePicture_Location()
Application.ScreenUpdating = False
Range("Z2").Select ' Modify to suit(If required)
Dim WB As Workbook
Dim Sh As Worksheet
Dim rng As Range
Dim mypic As Picture
Dim res As Variant, ans As Variant
Set WB = ActiveWorkbook
res = Application.GetOpenFilename("Image Files (*.jpg), *.jpg")
If res = False Then Exit Sub
Set Sh = ActiveSheet
Set rng = ActiveCell
Set mypic = Sh.Pictures.Insert(res) ' Do nto use. Only if you want a
sample picture over that cell
With mypic
.Top = rng.Top
.Left = rng.Left
.Locked = False
mypic.ShapeRange.LockAspectRatio = msoFalse ' False of True, up
to you. If True then remove one of the below modifications to size
mypic.ShapeRange.Width = 245.1 ' Modify Width to suit
mypic.ShapeRange.Height = 185 ' Modify Height to suit
ActiveCell.Offset(-1, 0).Value = res ' Location of the Picture
stored in Range("Z2").Offset(-1,0) or otherwise Range("Z1")
End With
Application.ScreenUpdating = True
End Sub



Sub Insert_Picture_into_sheet()
Application.ScreenUpdating = False
If Range("Z2").Value < "" Then
Range("Z2").Select
Set WB = ActiveWorkbook
res = Range("Z1").Value ' Finds location of Picture
If res = False Then Exit Sub
Set Sh = ActiveSheet
Set rng = ActiveCell
Set mypic = Sh.Pictures.Insert(res) ' Places the picture on the sheet over
the Activecell
With mypic
.Top = rng.Top
.Left = rng.Left
.Locked = False
mypic.ShapeRange.LockAspectRatio = msoFalse ' Same as previous
code
mypic.ShapeRange.Width = 245.1 ' Same as previous code
mypic.ShapeRange.Height = 185 ' Same as previous code

End With
End If
Application.ScreenUpdating = True
end Sub

If you wanted to you could use the "Private Sub
Worksheet_SelectionChange(ByVal Target As Range)" to do the Inserting of the
picture based on the value in the Activecell instead, to save manually
running that code.

Something lik:
If Range("Z2").value 100 then res=Range("Z1").value
If Range("Z2").value 75 and Range("Z1").value < 99 then
res=Range("Y1").value
etc.

Hope this assists you a bit.

Corey....
"vanan" wrote in message
...
I have a sheet1 that pickup up values from sheet2. I want to format cells
in
sheet1 to insert a particular graphics if certain condition is meet. E.g.
if
value <93% , insert red light, if value btw 94% and 97%, insert yellow
light
and so on. Its simple to highlight the cell with colors but replacing with
graphics is tough for me. How do I refer to a cell from a different excel
file which contains multiple sheets?

Thanks





All times are GMT +1. The time now is 05:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com