View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.misc
cluckers cluckers is offline
external usenet poster
 
Posts: 31
Default vlookup VBA code

The problem is that there is not going to be a vlookup value for all active
cells. When you run this is excel t returns a value of #N/A but in VBA it
returns an error. Do you know how to get around the error so it keeps
running the macro?

"Jacob Skaria" wrote:

Try the below

Dim srccom As Range
Set srccom = Workbooks("sourcedata.xls").Worksheets("Sheet1").R ange("F1:J100")
ActiveCell.Value = WorksheetFunction.VLookup(Range("A" & _
ActiveCell.Row), srccom, 5, 0)


If this post helps click Yes
---------------
Jacob Skaria


"cluckers" wrote:

Here is the code

Dim srccom As Range
Set srccom = Workbooks("sourcedata.xls").Worksheets("Sheet1").R ange("F1:J100")
ActiveCell.Value = WorksheetFunction.VLookup(Cells(ActiveCell, "A"), srccom,
5, 0)

Returns
Run-time error'13':
Type mismatch


"cluckers" wrote:

I am getting an error that says "type mismatch"

"Jacob Skaria" wrote:

Dim rngTemp As Range

Set rngTemp = Workbooks("soourcedata.xls"). _
Worksheets("Sheet1").Range("F1:I100")

ActiveCell.Value = WorksheetFunction.VLookup(Cells(ActiveCell, _
"A"), rngTemp, 4, 0)

If this post helps click Yes
---------------
Jacob Skaria


"cluckers" wrote:

thank Luke,

However I need more help if you could. For the second argument it is going
to be an another workbook called "sourcedata". the range is from F1 to the
furthers column to the right and the furthest row down. How would I write
that?

so far I have

ActiveCell.Value = WorksheetFunction.VLookup(Cells(ActiveCell, "A"),
soourcedata.xls.range(F1,..........), 4, False)

Not even sure if any of the second argument is correct.

thanks


"Luke M" wrote:

Cells(ActiveCell.Row,"A")
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"cluckers" wrote:

I am trying to use vlookup in a macro. I have to use

ActiveCell.Value = WorksheetFunction.VLookup(........)

because the active cell is in a column that will continuously move to the
right. Therefore I can not use a static command.

For the first argument of the vlookup how can I have it reference the cell
is column A of the same row. If I can get that part I think I can get the
rest.

Thanks