使用Excel中的“名称管理器”动态更改图像

问题描述 投票:0回答:1

我有一个动态行数的表。有一个特定的列可以根据旁边单元格的值更改图像。

我尝试过使用本指南:

https://www.youtube.com/watch?v=yHBQ9Qxli3M

但它只能用于特定行而不能动态使用。我尝试过使用:

=INDIRECT("RC[-1]",0)

在我的图像名称中,但似乎没有根据目标细胞进行更改。

我的excel文件的链接:

https://drive.google.com/open?id=1v1RXhdPYU4j2CqxgNEWUtJ8gHbZV33xN

excel excel-formula
1个回答
0
投票

还有另一种方法可以通过VBA来实现。您可以将此代码放在“Sheet1”下。它会检测何时对列M进行更改,然后从查找表中复制并粘贴图像。

注意:

  • 它仅在值1插入单元格时有效
  • 删除'1'值会删除图像
  • 向下拖动1个值将无效(尽管可以调整宏)。最好一次输入一个'1'值;)

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells, SelectedCells As Range, s As Shape
    Set KeyCells = Range("M13:M1000")
    Set SelectedCells = Range(Target.Address)

    If Not Application.Intersect(KeyCells, SelectedCells) Is Nothing Then
    'Place a 1 in the cell to insert an image
    If Application.Sum(Range(Target.Address)) = 1 Then        
      Sheets("Shapes").Shapes("Shape" & Range(Target.Address).Offset(0, -2).Value).Copy
      ActiveSheet.Paste
      Selection.Left = SelectedCells.Left
      Selection.Top = SelectedCells.Top
      SelectedCells.Select    
    Else 'Deletes the pictures if a 1 is not present
      For Each s In ActiveSheet.Shapes
        If Not Intersect(SelectedCells, s.TopLeftCell) Is Nothing Then
            s.Delete
        End If
      Next s 
    End If
    End If
    End Sub
© www.soinside.com 2019 - 2024. All rights reserved.