VBA Lookup Help

saschmeling

New Member
Joined
Jun 27, 2012
Messages
39
Can anyone tell me why this line of code is not working:

Code:
  ActiveCell.FormulaR1C1 = "=IF(RC[-5]>0,VLOOKUP(RC[-5],'C:\Users\Scott A. Schmeling\Google Drive\HCA Files\Projection Files\Projection Spreadsheets\Org 5110 Projections.xlsx'!Table2[#All],3),"")"

I keep getting an application defined or object defined error when I run it.

Here is the entire subroutine:

Code:
Sub Projections()

    Dim LR As Long
    Range("g7").Select
    ActiveCell.FormulaR1C1 = "=IF(RC[-5]>0,VLOOKUP(RC[-5],'C:\Users\Scott A. Schmeling\Google Drive\HCA Files\Projection Files\Projection Spreadsheets\Org 5110 Projections.xlsx'!Table2[#All],3),"")"
    LR = ActiveSheet.UsedRange.Rows.Count
    Range("G7").AutoFill Destination:=Range("G7:G" & LR)
    Columns("G:G").Select
    Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
 
End Sub

Basically, it should do the following.

Look at column A
If there is a number in column A
Look at the 0rg 5110 Projections Workbook Column 3
Return the appropriate number.


Open to any and all suggestions.

Thanks,
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
First a question. If you have the Org 5110 Projections workbook open when you run the code do you still get the error? Second if you do not define the vlookup to find only an exact match (your code adjusted to find the exact match below) you may be leaving yourself open to bad data, but that isn't always the case.

le2[#All],3,False)</pre>
 
Upvote 0
Thanks DidIDo_that,

Actually not being open was part of the issue. I have had to add a line to open the projections workbook. Then close it. Also I found out that once I added an extra set of "" at the end, it works.

The code is not perfect but it does get the job done right now.

If anyone has any cleanup suggestions would be appreciated!

Thanks,
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top