VBA Code needed for semi-complex VLookup

dpiano1984

New Member
Joined
Feb 8, 2013
Messages
14
Hello all,First of all this is my first post. I'm new to VBA, but I'm intermediate with excel and recently found the wonderful world of VisualBasic. Here's what I'm trying to doThere is a spreadsheet that I work on everyday where I pull data from another spreadsheet (this is a different spreadsheet everyday, but the task is repeated the same). I copy cells in E#:O# and paste them into D#:N#. I figured you could automate this by writing a code to perform a vlookup for each cell. The code I have so far is this: '''''''''''''''''''''''''''''' 'Message Box for File Browsing '''''''''''''''''''''''''''''' Dim myfile As String MsgBox ("Please Browse for the File That You Would like to Reference") myfile = Application.GetOpenFilename Range("D2").FormulaR1C1 = "=vlookup(rc1,][myfile]ACCRUAL BALANCE TOTALS'!C3:C5,3,FALSE)"-------------------the last line is repeated up until Range("N2") and I then have this code written for the rest:Range("D2:N2").Copy Destination:=Range("D3:N201") MsgBox ("Autofill of Worksheet Complete")-------------The main problem I keep having is the first line of my spreadsheet will return "N/A" and the rest will be perfect. The other problem is if there is an error in the first few lines it re-formats my sheet so that the columns are numerical instead of alphabetical. Is there an easier code I can write or do I need more parameters for VBA to abide by?
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,214,907
Messages
6,122,185
Members
449,071
Latest member
cdnMech

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