ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If statement to add picture based on cell value (https://www.excelbanter.com/excel-programming/412797-if-statement-add-picture-based-cell-value.html)

Scott

If statement to add picture based on cell value
 
Hello-

I have an if statement that should add a picture to cell A15 based on
the value of E6. When I run the code, the picture for the first IF
statement value always comes up (8-8.24) even though the value of E6
is 9.17. Any ideas?

Thanks-

Scott

Sub PIC()
Dim myCell As Range
Set myCell = Selection
Dim shp1 As Picture

On Error Resume Next

If Range("E6").Value <= "8" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\1.wmf").Select
Selection.Name = "a15 Picture"
ElseIf Range("E6").Value <= "8.25" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\2.wmf").Select
Selection.Name = "a15 Picture"
ElseIf Range("E6").Value <= "8.5" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\3.wmf").Select
Selection.Name = "a15 Picture"
ElseIf Range("E6").Value <= "8.75" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\4.wmf").Select
Selection.Name = "a15 Picture"
ElseIf Range("E6").Value <= "9" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\5.wmf").Select
Selection.Name = "a15 Picture"
ElseIf Range("E6").Value <= "9.25" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\6.wmf").Select
Selection.Name = "a15 Picture"

End If

myCell.Select
End Sub

Sam Wilson

If statement to add picture based on cell value
 
The value of E6 is a number, and you've got ... value<= "8"... where "8" is a
string.

The number 8 is < the string "8", alphabetically speaking. Remove the
quotation marks from your numbers and it should work.

Sam


"Scott" wrote:

Hello-

I have an if statement that should add a picture to cell A15 based on
the value of E6. When I run the code, the picture for the first IF
statement value always comes up (8-8.24) even though the value of E6
is 9.17. Any ideas?

Thanks-

Scott

Sub PIC()
Dim myCell As Range
Set myCell = Selection
Dim shp1 As Picture

On Error Resume Next

If Range("E6").Value <= "8" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\1.wmf").Select
Selection.Name = "a15 Picture"
ElseIf Range("E6").Value <= "8.25" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\2.wmf").Select
Selection.Name = "a15 Picture"
ElseIf Range("E6").Value <= "8.5" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\3.wmf").Select
Selection.Name = "a15 Picture"
ElseIf Range("E6").Value <= "8.75" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\4.wmf").Select
Selection.Name = "a15 Picture"
ElseIf Range("E6").Value <= "9" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\5.wmf").Select
Selection.Name = "a15 Picture"
ElseIf Range("E6").Value <= "9.25" Then
ActiveSheet.Shapes("a15 Picture").Delete
Range("a15").Select
ActiveSheet.Pictures.Insert("M:\custserv\CentreVuR eports\Images
\6.wmf").Select
Selection.Name = "a15 Picture"

End If

myCell.Select
End Sub



All times are GMT +1. The time now is 01:14 PM.

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