Results 1 to 3 of 3

Amend columns in a formula that lookup values from temp sheet

Threaded View

sukyb1 Amend columns in a formula... 08-09-2012, 05:00 AM
dilipandey Re: Desperately need to help... 08-09-2012, 05:04 AM
arlu1201 Re: Desperately need to help... 08-09-2012, 05:22 AM
  1. #1
    Registered User
    Join Date
    03-26-2009
    Location
    uk
    MS-Off Ver
    Excel 2003
    Posts
    6

    Amend columns in a formula that lookup values from temp sheet

    Hi...i have this code below....what is does is take columns BA:BB into a Sheet1 into a temp sheet and sort it so that Sheet1 column AX can be populated with a formula that looks for column A in Column BA and returns BB...but the lookup happens in the temp sheet..so column BA and BB are columns A and B in the temp sheet.

    I need to change it so that the AV is the column that has the lookup formula and AB is the column that has the value being looked up...i've tried to amend it but habe had no luck.


    Dim wsData As Worksheet, wsTemp As Worksheet
    Dim rng As Range
    
    Set wsData = ActiveSheet
    
    With wsData
    Set rng = .Range("BA1:BB" & .Cells(.Rows.Count, "BA").End(xlUp).Row)
    End With
    
    Set wsTemp = Worksheets.Add
    
    wsTemp.Range("A1").Resize(rng.Rows.Count, 2).Value2 = rng.Value2
    
    Set rng = wsTemp.Range("A1").Resize(rng.Rows.Count, 2)
    
    rng.Sort key1:=rng.Columns(1), order1:=xlAscending
    
    With wsData
    With .Range("A2:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    .Offset(, .Columns("AX:AX").Column - 1).FormulaR1C1 = _
    "=IF(LOOKUP(RC1,'" & rng.Parent.Name & "'!" & rng.Columns(1).Address(1, 1, xlR1C1) & ")=RC1" & _
    ",LOOKUP(RC1,'" & rng.Parent.Name & "'!" & rng.Columns(1).Address(1, 1, xlR1C1) & ",'" & _
    rng.Parent.Name & "'!" & rng.Columns(2).Address(1, 1, xlR1C1) & "),NA())"
    .Offset(, .Columns("AX:AX").Column - 1).Value2 = .Offset(, .Columns("AX:AX").Column - 1).Value2
    End With
    End With
    Last edited by sukyb1; 08-09-2012 at 06:24 AM.

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