+ Reply to Thread
Results 1 to 3 of 3

Vlookup and Formatting

  1. #1
    Registered User
    Join Date
    06-21-2005
    Posts
    10

    Vlookup and Formatting

    On Sheet1, I have data with cells that have different formatting (e.g. different text colors/bold/etc.). On Sheet 2, I have a vlookup formula that shows the data presented on Sheet 1, but without the formatting.

    Is it possible while using a vlookup formula to display both the data and the data's original formatting? If not, how else can I accomplish this? Thanks!!!

  2. #2
    JE McGimpsey
    Guest

    Re: Vlookup and Formatting

    Worksheet functions return values to their calling cells. They can't
    return formats.

    You could do the lookup in a VBA Event procedure to return both:

    Private Sub Worksheet_Calculate()
    'Assume lookup value is in A1, value and format
    'to be returned in B1
    'VLOOKUP equivalent: =VLOOKUP(A1,Sheet2!A:B,2,FALSE)
    Dim rFound As Range
    With Worksheets("Sheet2").Range("A:A")
    Set rFound = .Find( _
    What:=Range("A1").Value, _
    After:=.Cells(.Count), _
    LookIn:=xlValues, _
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False)
    End With
    Application.EnableEvents = False
    With Range("B1")
    If rFound Is Nothing Then
    .Value = CVErr(xlErrNA)
    .ClearFormats
    Else
    rFound.Offset(0, 1).Copy
    .PasteSpecial Paste:=xlPasteValues
    .PasteSpecial Paste:=xlFormats
    End If
    End With
    Application.EnableEvents = True
    End Sub



    In article <[email protected]>,
    peter_rivera
    <[email protected]> wrote:

    > On Sheet1, I have data with cells that have different formatting (e.g.
    > different text colors/bold/etc.). On Sheet 2, I have a vlookup formula
    > that shows the data presented on Sheet 1, but without the formatting.
    >
    > Is it possible while using a vlookup formula to display both the data
    > and the data's original formatting? If not, how else can I accomplish
    > this? Thanks!!


  3. #3
    Debra Dalgleish
    Guest

    Re: Vlookup and Formatting

    No, a VLookup formula can only return a value, not the formatting from
    the original cell.

    Perhaps you could use conditional formatting to format the cells, based
    on the value returned. There are instructions in Excel's Help, and here:

    http://www.contextures.com/xlCondFormat01.html

    peter_rivera wrote:
    > On Sheet1, I have data with cells that have different formatting (e.g.
    > different text colors/bold/etc.). On Sheet 2, I have a vlookup formula
    > that shows the data presented on Sheet 1, but without the formatting.
    >
    > Is it possible while using a vlookup formula to display both the data
    > and the data's original formatting? If not, how else can I accomplish
    > this? Thanks!!!
    >
    >



    --
    Debra Dalgleish
    Excel FAQ, Tips & Book List
    http://www.contextures.com/tiptech.html


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1