【发布时间】:2024-01-24 04:22:01
【问题描述】:
我有一个带有宏的工作表,当我更改单元格 E5 中的值时,会自动填充 sheet1 中的某些字段,从其他工作表上的表中搜索并返回值 - sheetTable )。
我现在的目标是在 sheetTable 上的一列中选择一系列值,并将它们中的每一个分配给 sheet1 上的单元格 E5,然后打印每个值。
假设我选择了 3 个值分别为 45、50 和 66 的单元格。当我运行宏时,它会将 45 分配给单元格 E5 并打印 sheet1,然后它会将 50 分配给单元格 E5并打印 sheet1,最后将 66 分配给单元格 E5 并打印 sheet1。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Dim shape As Excel.shape
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("e5")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
For Each shape In ActiveSheet.Shapes
shape.Delete
Next
InsertPictureInRange Range("f2").Value & Range("e5").Value & ".jpg", _
Range("c9")
InsertPictureInRange Range("f2").Value & Range("e5").Value & "_1.jpg", _
Range("i9")
If Range("e5").Value = "" Then Exit Sub
End If
End Sub
【问题讨论】: