我有一个包含值O和G的表的Excel文件,我想用宏用橙色图标替换O,用绿色图标替换G
我不知道如何读取每个单元格的值O和G,并用它们各自的图像替换它们。
Private Sub CommandButton1_Click()
For Each c In Worksheets("Summary (2)").Range("A1:D10")
If c.Value = 0 Then
c.Value = Orange
ElseIf c.Value = G Then
c.Value = "Green"
Else
c.Value = ""
End If
Next c
End Sub
答案 0 :(得分:0)
你就是这样做的,
Private Sub CommandButton1_Click()
Application.CopyObjectsWithCells = True
For Each c In Worksheets("Sector Summary (2)").Range("A1:H100")
If c.Value = "O" Then
Sheets("master").Cells(1, 2).Copy
c.Select
ActiveSheet.Paste
ElseIf c.Value = "G" Then
Sheets("master").Cells(2, 2).Copy
c.Select
ActiveSheet.Paste
ElseIf c.Value = "R" Then
Sheets("master").Cells(3, 2).Copy
c.Select
ActiveSheet.Paste
Else
c.Value = c.Value
End If
Next c
End Sub