+ Reply to Thread
Results 1 to 5 of 5

Thread: Formula Reffering to Different Sheets

  1. #1
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Formula Reffering to Different Sheets

    Hello all,

    The following code retrieves values from sheet "WERKBLAD".
    Now I'd like to extend it with 2 more sheets "WERKBLAD2" and "WERKBLAD3".

    Is it possible to change the formula below so it looks for matches in all 3 the sheets.
    The layout of all 3 the sheets are the same.


    With Worksheets("Urenstaat")
        
        TopRow = .Range("D" & Rows.Count).End(xlUp).Row + 1
        lastrow = .Range("A" & Rows.Count).End(xlUp).Row
        
        If TopRow < lastrow Then
            With .Range("D" & TopRow & ":D" & lastrow)
                .FormulaR1C1 = "=IF(RC[-3]=""Werknemer:"","""",VLOOKUP(INDEX(WERKBLAD!R6C4:R5000C256,MATCH(RC[-3],WERKBLAD!R6C2:R5000C2,0),MATCH(LOOKUP(2,1/(R6C1:RC[-3]=""Werknemer:""),R6C2:RC[-2]),WERKBLAD!R5C4:R5C256,0)),IMPORT!R3C7:R300C11,2,FALSE))"
                .Value = .Value
            End With
        End If
    End With

  2. #2
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Re: Formula Reffering to Different Sheets

    Impossible?

  3. #3
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Re: Formula Reffering to Different Sheets

    All help is welcome

  4. #4
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: Formula Reffering to Different Sheets

    Well, I don't know a lot about what worksheet functions do, and the following code is not tested to your workbook criteria, and it may be a little crude compared to what the gurus would do, here is a hopeful:
    Sub Jonathan78()
    
    With Worksheets("Urenstaat")
        TopRow = .Range("D" & Rows.Count).End(xlUp).Row + 1
        lastrow = .Range("A" & Rows.Count).End(xlUp).Row
        
        If TopRow < lastrow Then
            With .Range("D" & TopRow & ":D" & lastrow)
                .FormulaR1C1 = "=IF(RC[-3]=""Werknemer:"","""",VLOOKUP(INDEX(WERKBLAD!R6C4:R5000C256,MATCH(RC[-3],WERKBLAD!R6C2:R5000C2,0),MATCH(LOOKUP(2,1/(R6C1:RC[-3]=""Werknemer:""),R6C2:RC[-2]),WERKBLAD!R5C4:R5C256,0)),IMPORT!R3C7:R300C11,2,FALSE))"
                .Value = .Value
            End With
        End If
    End With
    
    With Worksheets("Urenstaat")
        TopRow = .Range("D" & Rows.Count).End(xlUp).Row + 1
        lastrow = .Range("A" & Rows.Count).End(xlUp).Row
        
        If TopRow < lastrow Then
            With .Range("D" & TopRow & ":D" & lastrow)
                .FormulaR1C1 = "=IF(RC[-3]=""Werknemer:"","""",VLOOKUP(INDEX(WERKBLAD2!R6C4:R5000C256,MATCH(RC[-3],WERKBLAD2!R6C2:R5000C2,0),MATCH(LOOKUP(2,1/(R6C1:RC[-3]=""Werknemer:""),R6C2:RC[-2]),WERKBLAD2!R5C4:R5C256,0)),IMPORT!R3C7:R300C11,2,FALSE))"
                .Value = .Value
            End With
        End If
    End With
    
    With Worksheets("Urenstaat")
        TopRow = .Range("D" & Rows.Count).End(xlUp).Row + 1
        lastrow = .Range("A" & Rows.Count).End(xlUp).Row
        
        If TopRow < lastrow Then
            With .Range("D" & TopRow & ":D" & lastrow)
                .FormulaR1C1 = "=IF(RC[-3]=""Werknemer:"","""",VLOOKUP(INDEX(WERKBLAD3!R6C4:R5000C256,MATCH(RC[-3],WERKBLAD3!R6C2:R5000C2,0),MATCH(LOOKUP(2,1/(R6C1:RC[-3]=""Werknemer:""),R6C2:RC[-2]),WERKBLAD3!R5C4:R5C256,0)),IMPORT!R3C7:R300C11,2,FALSE))"
                .Value = .Value
            End With
        End If
    End With
    
    End Sub
    Please leave a message after the beep!

  5. #5
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Re: Formula Reffering to Different Sheets

    Hello Mordred,

    Thanks for trying but this doesn't work.

    The code inserts the formula.
    Your code just overwrites the others the formula.

    Any other ideas?

+ 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.2.0