我有个问题。我需要编写选择 E 列中的值的宏。所选项目的值应介于单元格 T2 和 U2 中的值之间。选择后,宏应绘制图表。
我尝试了 3 种方法:
第一种方法:
Sub wykres1()
Dim rng As Range
Dim cell As Range
Set rng = Range("E1", Range("E65536").End(xlUp))
For Each cell In rng
If cell.Value > "T2" and cell.value < "U2" Then Cell.Select
With Selection
ActiveSheet.Shapes.AddChart2
End With
Next cell
End Sub
Wykres1 不起作用,因为带有的行以
if红色突出显示。
第二种方法:
Sub wykres2()
Dim rng As Range
Dim cell As Range
Set rng = Range("E1", Range("E65536").End(xlUp))
For Each cell In rng
If cell.Value > ActiveSheet.Cell(2,20).Value and cell.value < ActiveSheet.Cell(2,21).Value Then Cell.Select
With Selection
ActiveSheet.Shapes.AddChart2
End With
Next cell
End Sub
Wykres2 不起作用,因为带有的行以
if红色突出显示。
第三种方法:
Sub wykres3()
Dim rng As Range
Dim cell As Range
Set rng = Range("E1", Range("E65536").End(xlUp))
For Each cell In rng
If cell.value > -35 And cell.value < -32 Then cell.Select
With Selection
ActiveSheet.Shapes.AddChart2
End With
Next cell
End Sub
Wykres3 运行后冻结。当我删除带有绘制图表的部分时,宏选择一个单元格而不是具有选定值的范围。在这里,我将值放在宏 (-35) (-32) 中 - 但我对从单元格 (T2) (U2) 中放置值的可能性感兴趣。
正如我所提到的 - 我需要创建宏来选择 E 列中的单元格,其值介于单元格 T2 和 U2 中的值之间。选择宏后必须绘制图表。
感谢您的帮助。