Question : Using VLOOKUP with format color

Hello,

I'm using VLOOKUP to get data from one spreadsheet to another.  I also wish to retrieve the formatting of the cell from which the data is culled—just the color.  Any suggestions?  

Answer : Using VLOOKUP with format color

whart91426,

It seems nonsense... but works. But  the drawback is that you should put the values manually or call another macro to loop through the cells.

The below code will search Shee2!A1:A10 for a value of 5 and returns the value and color of the cell in column B (A+col= A+1 = B) which corresponds to the cell of value 5 in column A

1. Press Alt + F11 to goto VBA.
2. Insert --> Module.
3. Paste the code given...
4. Press Alt + F11 again to come back to Excel.
5. Press Alt + F8 to goto macros dialog.
6. Select the macro and click Run

Sub MyLookUp()
    Dim findrng As Range
    Dim val As Variant
    Dim lookrng As Range
    Dim cel As Range
    Dim curcel As Range
   
    Set findrng = Sheet2.[A1:A10]
    col = 1
    val = 5
    Set curcel = Sheet1.[A1]
   
    For Each cel In findrng
        If (cel = val) Then
            curcel.Font.Color = cel.Offset(0, col).Font.Color
            curcel = cel.Offset(0, col)
            Exit For
        End If
    Next
End Sub

Random Solutions  
 
programming4us programming4us