假設在A列(來源COL)的所有單元格粘貼有相同的顏色...否則會得到黑色顏色的目標列(C)
Range("C:C").Interior.Color = Range("A:A").Interior.Color
更新-1 COL通過關口
Sub foo2()
Dim ARows, CRows As Long
Dim SourceRange, TargetRange As String
Dim SFirstRow, TfirstRow As Integer ' these are the starting points for the coluring of the col, in case you have header which is not colured.
SFirstRow = 2 ' if you have header which is to be ignored... otherwise make it 1
TfirstRow = 2
ARows = Range("A" & Rows.Count).End(xlUp).Row
CRows = Range("C" & Rows.Count).End(xlUp).Row
SourceRange = "A" & SFirstRow & ":A" & ARows
TargetRange = "C" & TfirstRow & ":C" & CRows
Range(TargetRange).Interior.Color = Range(SourceRange).Interior.Color
End Sub
更新2到做逐行
Sub foo2()
Dim ARows, CRows As Long
Dim SourceRange, TargetRange As String
Dim SFirstRow, indexS As Integer ' these the starting points for the coluring of the col, in case you have header which is not colured.
SFirstRow = 1
ARows = Range("A" & Rows.Count).End(xlUp).Row
CRows = Range("C" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For indexS = SFirstRow To ARows Step 1
ActiveSheet.Range("B" & indexS).Interior.Color = ActiveSheet.Range("A" & indexS).Interior.Color
ActiveSheet.Range("C" & indexS).Interior.Color = ActiveSheet.Range("A" & indexS).Interior.Color
ActiveSheet.Range("D" & indexS).Interior.Color = ActiveSheet.Range("A" & indexS).Interior.Color
Next
Application.ScreenUpdating = True
End Sub`
更新-3,此代碼獲取您的excelsheet和顏色使用列B(可改變)的最後一列到你有最後使用的列您的工作表
Sub foo3()
Dim ATotalRows As Long
Dim SourceRange, TargetRange As String
Dim TargetSheet As Worksheet
Dim SFirstRow, SFirstCol, indexRows, indexCols, TotalCols As Long ' these the starting points for the coluring of the col, in case you have header which is not colured.
Set TargetSheet = ThisWorkbook.Worksheets("Sheet1") ' Enter The name of your worksheet here
SFirstRow = 1 ' The Row from where to start
SFirstCol = 2 ' The Column from where to start coloring, in this case from the second column- 'B'
SLastCol= 10 ' index number of last col to be colored
ATotalRows = TargetSheet.Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For indexRows = SFirstRow To ATotalRows Step 1
For indexCols = SFirstCol To SLastCol Step 1 ' starts coluring form B
TargetSheet.Cells(indexRows, indexCols).Interior.Color = TargetSheet.Range("A" & indexRows).Interior.Color
Next
Next
Application.ScreenUpdating = True
End Sub
子FilterBold() 昏暗myRange爲靶場 對錯誤轉到取消 設置myRange = Application.InputBox(提示:= 「請選擇範圍」,標題:= 「的InputBox方法」 中輸入:= 8) myRange 。選擇 Application.ScreenUpdating =假 對於每個myRange在選擇 如果myRange.Font.Bold = TRUE,則 myRange.Columns( 「b:GR」)。Font.Bold =真 結束如果 接着myRange 應用。 ScreenUpdating = True 已取消: End Sub –