I have the chart below with numbers, below the number I want to insert an image and have the image change every time the number is changed, I plan to have 4 separate rows where the image populates. Below the source code I have. I am having two problems. below each number should be an image that automatically populates once the number is added.
1-Apply to multiple columns and rows
2-Mix-match type run-time error
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myPict As Picture
Dim PictureLoc As Integer
If Target.Address = Range("A2").Address Then
ActiveSheet.Pictures.Delete
PictureLoc = "C:\Users\isaac\Downloads\inser\" & Range("A2").Value & ".jpg"
With Range("A3")
Set myPict = ActiveSheet.Pictures.Insert(PictureLoc)
.RowHeight = myPict.Height
myPict.Top = .Top + .Height / 2 - myPict.Height / 2
myPict.Left = .Left + .Width / 2 - myPict.Width / 2
myPict.Placement = xlMoveAndSize
End With
End If
End Sub
1-Apply to multiple columns and rows
2-Mix-match type run-time error
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myPict As Picture
Dim PictureLoc As Integer
If Target.Address = Range("A2").Address Then
ActiveSheet.Pictures.Delete
PictureLoc = "C:\Users\isaac\Downloads\inser\" & Range("A2").Value & ".jpg"
With Range("A3")
Set myPict = ActiveSheet.Pictures.Insert(PictureLoc)
.RowHeight = myPict.Height
myPict.Top = .Top + .Height / 2 - myPict.Height / 2
myPict.Left = .Left + .Width / 2 - myPict.Width / 2
myPict.Placement = xlMoveAndSize
End With
End If
End Sub
3 | 2 | 1 |
1 | 1 | 2 |