#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Vlookup

Hello,

I am trying to have a MACRO automatically do a VLOOKUP and paste the
results into my spreadsheet. I have input the formula manually and it
works, so I know the file names and ranges are correct.

Column A is the data to lookup and Column B is where I want the VLOOKUP
to enter the results.

My futile effort for a code is below:

Worksheets("Sheet 1").Activate

Set CurrentCell = Range("A2")
Do While Not IsEmpty(CurrentCell)
Set CurrentCell = CurrentCell.Offset(0, 1)
Set NextCell = CurrentCell.Offset(1, 0)

Range("B2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-1], '[FILE
NAME.xls]Sheet1'!$A$2:$B$1147,1,FALSE)"
CurrentCell.Copy
Selection.PasteSpecial Paste:=x1Values
Application.CutCopyMode = False
Set CurrentCell = NextCell

Loop

Next


End Sub


I Get a Run-time error 1004 - Application Defined or object defined
error.

Does anyone have any suggestions? I know this is probably an easy fix
but it is driving me crazy.

Thanks



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Vlookup

Steve,

You have mixed references in your formula

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-1], '[FILE
NAME.xls]Sheet1'!$A$2:$B$1147,1,FALSE)"

Change to
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-1], _
'[FILENAME.xls]Sheet1'!R1C1:R1147C2,1,FALSE)"

--
sb
"STEVEB" wrote in message
...
Hello,

I am trying to have a MACRO automatically do a VLOOKUP and paste the
results into my spreadsheet. I have input the formula manually and it
works, so I know the file names and ranges are correct.

Column A is the data to lookup and Column B is where I want the VLOOKUP
to enter the results.

My futile effort for a code is below:

Worksheets("Sheet 1").Activate

Set CurrentCell = Range("A2")
Do While Not IsEmpty(CurrentCell)
Set CurrentCell = CurrentCell.Offset(0, 1)
Set NextCell = CurrentCell.Offset(1, 0)

Range("B2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-1], '[FILE
NAME.xls]Sheet1'!$A$2:$B$1147,1,FALSE)"
CurrentCell.Copy
Selection.PasteSpecial Paste:=x1Values
Application.CutCopyMode = False
Set CurrentCell = NextCell

Loop

Next


End Sub


I Get a Run-time error 1004 - Application Defined or object defined
error.

Does anyone have any suggestions? I know this is probably an easy fix
but it is driving me crazy.

Thanks



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Vlookup

Steve,

Thanks for the help, The formula works great!



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Vlookup

Steve,

Glad to be of help!

Keep on Exceling...

--
sb
"STEVEB" wrote in message
...
Steve,

Thanks for the help, The formula works great!



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Vlookup

Dim rng as Range
With Worksheets("Sheet 1")
set rng = .Range(.Cells(2,1),.Cells(rows.count,1).End(xlup))
End With
rng.offset(0,1).Formula = _
"=VLOOKUP(A2," & _
"'[FILENAME.xls]Sheet1'!" & _
"$A$2:$B$1147,1,FALSE)"

rng.offset(0,1).Formula = rng.Offset(0,1).Value

Should do what you want.

One of your problems was/is you were mixing A1 notation and using
FormulaR1C1

You are using a 3rd argument of 1 in your vlookup - so are you not just
returning the a value that matches the value in Column A?

--
Regards,
Tom Ogilvy


STEVEB wrote in message
...
Hello,

I am trying to have a MACRO automatically do a VLOOKUP and paste the
results into my spreadsheet. I have input the formula manually and it
works, so I know the file names and ranges are correct.

Column A is the data to lookup and Column B is where I want the VLOOKUP
to enter the results.

My futile effort for a code is below:

Worksheets("Sheet 1").Activate

Set CurrentCell = Range("A2")
Do While Not IsEmpty(CurrentCell)
Set CurrentCell = CurrentCell.Offset(0, 1)
Set NextCell = CurrentCell.Offset(1, 0)

Range("B2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-1], '[FILE
NAME.xls]Sheet1'!$A$2:$B$1147,1,FALSE)"
CurrentCell.Copy
Selection.PasteSpecial Paste:=x1Values
Application.CutCopyMode = False
Set CurrentCell = NextCell

Loop

Next


End Sub


I Get a Run-time error 1004 - Application Defined or object defined
error.

Does anyone have any suggestions? I know this is probably an easy fix
but it is driving me crazy.

Thanks



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



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
If (Vlookup 0) working, but what if Vlookup cell does not exist Steve Excel Worksheet Functions 18 November 18th 09 07:33 PM
VLookUp - Does the VLookUp return the exact information? Cpviv Excel Worksheet Functions 2 October 28th 08 09:57 AM
Combine VLOOKUP and IF function so #NA isn't returned as a value from VLOOKUP buffgirl71 Excel Discussion (Misc queries) 12 November 14th 06 11:36 PM
Vlookup -=VLOOKUP(F9,LookUp1!$A$2:$B$1504,2,FALSE) MikeR-Oz New Users to Excel 1 March 22nd 06 09:01 AM
Vlookup info being used without vlookup table attached? Excel Worksheet Functions 0 January 25th 05 10:43 AM


All times are GMT +1. The time now is 07:10 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"