Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default worksheetfunction

hi,
i'm trying to use vlookup in vba, bt i can't get it to work. here's the thing:

Dim count As Integer
Dim n As Integer
Dim table As String
Dim look As String
Dim column As Integer

count = Workbooks("BDs").Worksheets("bd_lx").Range("A2").V alue
column = 3
For n = 4 To count
look = Workbooks("BDs").Worksheets("bd_lx").Range("B" & n).Value
table = Workbooks("BDs").Worksheets("bd_lx").Range("A" & n).Value

Application.WorksheetFunction.VLookup(look, rg, column, False).Select
Selection.Copy
Range("B:" & n).Select
Selection.End(xlRight).Select
ActiveCell.Offset(1, 0).Activate
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Next n

is it 'cause the variable array? and probably is not a range?
how can i put it right?

thanks a million,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default worksheetfunction

Vlookup returns string or number from column 3 - not the location of the
cell. Use match in conjunction with your rg

this assumes rg is a single column range object.

if it is an array, you can't use range methods like Copy and select

res = application.Match(look, rg, 0)
if not iserror(res) then
rg(res).Select

or
rg(res,3).Select

Clarify what rg is


--
Regards,
Tom Ogilvy

"devnext" wrote in message
...
hi,
i'm trying to use vlookup in vba, bt i can't get it to work. here's the

thing:

Dim count As Integer
Dim n As Integer
Dim table As String
Dim look As String
Dim column As Integer

count = Workbooks("BDs").Worksheets("bd_lx").Range("A2").V alue
column = 3
For n = 4 To count
look = Workbooks("BDs").Worksheets("bd_lx").Range("B" & n).Value
table = Workbooks("BDs").Worksheets("bd_lx").Range("A" & n).Value

Application.WorksheetFunction.VLookup(look, rg, column, False).Select
Selection.Copy
Range("B:" & n).Select
Selection.End(xlRight).Select
ActiveCell.Offset(1, 0).Activate
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,

SkipBlanks:= _
False, Transpose:=False
Next n

is it 'cause the variable array? and probably is not a range?
how can i put it right?

thanks a million,



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
WorksheetFunction help Ayo Excel Discussion (Misc queries) 2 July 20th 08 10:48 PM
Can't use WorksheetFunction Yossi Excel Discussion (Misc queries) 5 January 25th 06 10:07 PM
WorksheetFunction with VBA Ghislain Marcotte Excel Discussion (Misc queries) 2 February 13th 05 07:08 AM
Worksheetfunction MATCH Yves Janssens Excel Programming 2 October 6th 03 03:25 PM
Using Application.WorksheetFunction.Ln(...) in VBA doco Excel Programming 4 August 25th 03 01:08 PM


All times are GMT +1. The time now is 09:12 PM.

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

About Us

"It's about Microsoft Excel"