vb编程根据sheet1条件在sheet2中画线
时间: 2023-05-19 14:01:45 浏览: 181
您可以使用 VBA 编写代码来实现此功能。以下是一个示例代码:
Sub DrawLine()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lastRow As Long
Dim i As Long
Set ws1 = ThisWorkbook.Worksheets("Sheet1")
Set ws2 = ThisWorkbook.Worksheets("Sheet2")
lastRow = ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row
For i = 2 To lastRow
If ws1.Cells(i, "A").Value = "条件" Then
With ws2.Shapes.AddLine(ws1.Cells(i, "B").Left, ws1.Cells(i, "B").Top, ws1.Cells(i, "C").Left, ws1.Cells(i, "C").Top)
.Line.ForeColor.RGB = RGB(255, 0, 0) '设置线条颜色为红色
End With
End If
Next i
End Sub
此代码将在 Sheet2 中根据 Sheet1 中的条件绘制线条。如果 Sheet1 中的 A 列中的单元格包含“条件”,则将在 Sheet2 中绘制从 B 列到 C 列的线条。您可以根据需要更改代码中的条件和线条颜色。
阅读全文