0
我用宏@LondonRob發佈in this SO questionVLOOKUP複製單元格的顏色 - 錯誤的格式返回
我有一個問題,如果一個值重複,它拉的原始事件的顏色,而不是實際查找的值。因此,如果Item1在C列1.27中保留一個值,並且字體顏色爲粉紅色,並且item4在列C中保存的值爲1.27,並且字體顏色爲藍色,那麼當我在vlookup item4的1.27上運行宏時,它將變成粉色而不是藍色。
代碼的鍵位是在這裏:
Private Sub copyLookupFormatting(destRange As Range)
' Take each cell in destRange and copy the formatting
' from the destination cell (either itself or
' the vlookup target if the cell is a vlookup)
Dim destCell As Range
Dim srcCell As Range
For Each destCell In destRange
Set srcCell = getDestCell(destCell)
copyFormatting destCell, srcCell
Next destCell
End Sub
Private Sub copyFormatting(destCell As Range, srcCell As Range)
' Copy the formatting of srcCell into destCell
' This can be extended to include, e.g. borders
destCell.Font.Color = srcCell.Font.Color
destCell.Font.Bold = srcCell.Font.Bold
destCell.Font.Size = srcCell.Font.Size
destCell.Interior.Color = srcCell.Interior.Color
End Sub
Private Function getDestCell(fromCell As Range) As Range
' If fromCell is a vlookup, return the cell
' pointed at by the vlookup. Otherwise return the
' cell itself.
Dim srcColNum As Integer
Dim srcRowNum As Integer
Dim srcRange As Range
Dim srcCol As Range
srcColNum = extractLookupColNum(fromCell)
Set srcRange = extractDestRange(fromCell)
Set srcCol = getNthColumn(srcRange, srcColNum)
srcRowNum = Application.Match(fromCell.Value, srcCol, 0)
Set getDestCell = srcRange.Cells(srcRowNum, srcColNum)
End Function
請註明您就顯示什麼錯誤,而不是隻把樣本文件。 – Tony 2014-12-06 14:35:49
請將錯誤複製到您的問題中,以備將來參考。同時顯示你到目前爲止所嘗試的代碼。 – 2014-12-06 14:35:59