• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Using A Macro to Pull Data Into Excel

VBA_BB

New Member
Howdy,

I've used an if statement that creates the name of a .txt file based on a # of inputs that the user will be specifying with drop down arrows. I have assembled a database of these .txt files in a specific folder on my computer. I would like the macro to read the .txt file that is created in the specific cell and then pull that data into excel.

In my first attempt, I tried to accomplish by:
1) Record Macro
2) Copy the text file name from the cell
3) Clicking get data from text/csv
4) Pasting the file name
5) Loading into desired location
6) Stop recording

Now, this macro will run for the specific file that I selected but if the file name changes in the cell that creates the .txt file name by changing the various inputs and then running the macro, it still pulls in the data from the file that was used when creating the macro. I've looked at the VBA code and it looks like instead of creating a situation where it copies from the cell with the .txt file name each time, it just used the original file. I'm not sure how to get around this. I'm pretty new to VBA.

Any thoughts?

Thanks in advance for any help!
 
you should amend your vba code in following manner:
1. pass your desired filename in a variable,
2. then use that variable while executing your get data query.

hope this helps...
 
Back
Top