Macro Vlookup Code

ssheys1

New Member
Joined
May 11, 2012
Messages
1
Hi,

I am trying to update an old macro and only have a basic knowledge of VBA. Each month we receive input files from multiple sources. Each file has data on a "Current Fcst" tab. Dates are in column C and Data resides in various columns moving out. The format is always the same, new dates are simply added to the bottom.

The existing macro copies a set range from each file into a consolidated sheet. The issue with this is that we continually pull expired data and have no protection against changes to the input format. I would like to alter the macro to use a vlookup on the date in column C (referenceing the date in column A in the consolidation tab.) Since the headers do not change it is okay to simply ref the number of columns to count over, however I would not be averse to an hlookup within the vlookup.

Here is my current code:

Sub Copy_ST_Example()
Dim wrkbkincurr As Workbook
Dim wrkbkcurr As Workbook
Dim wrkshtin As Worksheet
Dim str As String
Set wrkbkcurr = ActiveWorkbook
str = wrkbkcurr.Sheets("ST All in").Cells(1, 2)
Set wrkbkincurr = Workbooks.Open(Trim(str), no)
Set wrkshtin = wrkbkincurr.Sheets("Current Fcst")
wrkshtin.Activate


wrkshtin.Range ("R102:R209")
Result = Application.WorksheetFunction.VLookup(Value, Range, 3, False)
wrkbkcurr.Sheets("ST All in").Activate
Range("A3").Select

Set wrkshtin = Nothing
wrkbkcurr.Save
wrkbkincurr.Close False
Set wrkbkincurr = Nothing

End Sub


The location of the input file is identifed in row 2 (EX: C:\Documents and Settings\Desktop\LossModel_example.xls).

I will create a seperate sub for each input file changing the reference.


Once this data is in these files there are many other processes performed, so linking to each file is not an option as the size explodes.

Thanks for your help!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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