写一个用excel的vba提取有颜色的单元格内容到第十三列的代码
时间: 2023-02-25 17:16:43 浏览: 345
以下是一段使用 VBA 代码,它可以提取带有颜色的单元格的内容,并将其输出到第十三列:
```
Sub ExtractColoredCells()
Dim i As Long
Dim j As Long
Dim lastRow As Long
Dim lastCol As Long
Dim cellColor As Long
Dim targetCol As Long
targetCol = 13
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To lastRow
For j = 1 To lastCol
cellColor = ActiveSheet.Cells(i, j).Interior.Color
If cellColor <> xlNone Then
ActiveSheet.Cells(i, targetCol).Value = ActiveSheet.Cells(i, j).Value
End If
Next j
Next i
End Sub
```
您可以将此代码复制并粘贴到 Excel 的 VBA 编辑器中,并运行它。在运行代码后,您将看到第十三列已填充具有颜色的单元格的内容。
阅读全文