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

Hi all.

I am currently working on a code that will input the vlookup function in specified cells. The code works fine if given a static range in the arguments for vlookup. However, I am attempting to make it dynamic, as I will need to apply this macro across multiple workbooks and the sheet ranges are not constant. However, my attempts have yielded no success.

The code is as follows:

Sub LookingUp(A)
Application.ScreenUpdating = False
ActiveWorkbook.Worksheets("MatchingNo").Activate
With ActiveWorkbook.Worksheets("MatchingNo")
Dim LastColumn As Long
Dim LastRow As Long
'Dim SM35Range As Range
Dim LastRow2 As Long
Dim LastColumn2 As Long
LastRow2 = ActiveWorkbook.Worksheets("SM35").UsedRange.Rows.C ount
LastColumn2 = ActiveWorkbook.Worksheets("SM35").UsedRange.Column s..Count
LastColumn = .UsedRange.Columns.Count
LastRow = .UsedRange.Rows.Count
For i = 2 To LastRow
For j = 2 To LastColumn
.Cells(i, j).Formula = Application.WorksheetFunction.VLookup(Cells(i, 1), ActiveWorkbook.Worksheets("SM35").Range(Cells(5, 1), Cells(LastRow2, LastColumn2)), j + 1, False)
Next j
Next i
Columns.AutoFit
ActiveWorkbook.Worksheets("MatchingNo").Range(Cell s(1, 1), Cells(LastRow, LastColumn)).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End With

ActiveWorkbook.Worksheets("MatchingNo").Activate
ActiveWorkbook.Worksheets("MatchingNo").Range("A1" ).Select
Application.ScreenUpdating = True
End Sub

Any input is much appreciated.

Thank you and regards.
 
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 01:51 AM.

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"