Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Referring a dynamic range in for Application.WorksheetFunction.Vlookup

Try...


Sub LookingUp_A()
Dim rngTarget As Range, rngLookup As Range, sFormula$

With ActiveWorkbook.Worksheets("MatchingNo").UsedRange
Set rngTarget = .Offset(1, 1).Resize(.Rows.Count - 1, _
.Columns.Count - 1)
End With

With ActiveWorkbook.Worksheets("SM35").UsedRange
'Lookup range starts at $A5 and stops at the last row/col
Set rngLookup = .Offset(4, 1).Resize(.Rows.Count - 4, _
.Columns.Count - 1)
End With
'Formula needs to self-adjust to its row in "A",
'so make its ref col-absolute/row-relative.
sFormula = "=VLOOKUP($A2,SM35!" & rngLookup.Address _
& ",COLUMN()+1,False)"

Application.ScreenUpdating = False
On Error GoTo ErrExit
With rngTarget
.Formula = sFormula: .Columns.AutoFit
.HorizontalAlignment = xlCenter: .VerticalAlignment = xlCenter
End With

ErrExit:
Set rngTarget = Nothing: Set rngLookup = Nothing
Application.ScreenUpdating = True
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble referring to a (dynamic) named range on another Excel shee jrbor76 Excel Programming 2 August 13th 09 03:48 PM
Need help with Application.WorksheetFunction Ayo Excel Discussion (Misc queries) 4 May 14th 08 11:13 PM
Application.WorksheetFunction.VLookup (Plz Help) Raj[_11_] Excel Programming 4 July 4th 07 01:37 PM
Formula referring to a dynamic range in a different workbook mr tom Excel Worksheet Functions 6 March 29th 07 08:56 AM
application.worksheetfunction.vlookup JulieD Excel Programming 5 August 12th 04 04:42 PM


All times are GMT +1. The time now is 07:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"