Import CSV file using VBA

VBA_fanatic

New Member
Joined
Feb 5, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi all,

I am pulling a CSV file from one of our online platforms and pasting it into a sheet called (Expenses) & on the same sheet, I'm inputting some GL codes. The workbook has 3 sheets, the majority of the info from the Expenses sheet is taken and automatically(formulae driven) copied to sheet 2 called (Transactions) that will further be copied to Accounting Software.

My question is -: I want to create a VBA to import the CSV file that I download each day. My mission is to import the CSV in Expenses Sheet from the range B1 to anywhere. Also, I want to set up the import button for the whole Macro on Sheet 1 called (Import report). Can anyone help me?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi VBA_fanatic
Just creat a button and after creating click new then make sure this code is in the button code
VBA Code:
Sub Button1_Click()
    Set mycsv = Workbooks.Open(Application.GetOpenFilename(, , "Choose CSV"))
    mycsv.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Expenses").Range("B1")
End Sub
 
Upvote 0
Hi VBA_fanatic
Just creat a button and after creating click new then make sure this code is in the button code
VBA Code:
Sub Button1_Click()
    Set mycsv = Workbooks.Open(Application.GetOpenFilename(, , "Choose CSV"))
    mycsv.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Expenses").Range("B1")
End Sub
Thanks for setting up the code for me!

However I was successfully able to create a button but when I tried to import the CSV it didn’t get copied. Run Time error ‘1004’ showed up on me. I did exactly same what you suggested.
 
Upvote 0
Hi VBA_fanatic
Just creat a button and after creating click new then make sure this code is in the button code
VBA Code:
Sub Button1_Click()
    Set mycsv = Workbooks.Open(Application.GetOpenFilename(, , "Choose CSV"))
    mycsv.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Expenses").Range("B1")
End Sub
Thanks for setting up the code for me!

However I was successfully able to create a button but when I tried to import the CSV it didn’t get copied. Run Time error ‘1004’ showed up on me. I did exactly same what you suggested
 
Upvote 0
1004 just means your trying to do something with a reference that isn't cannected to anything. I need to know where it stops in your code, so could you please run your code again and when it stops click debug, you'll see the line in yellow. I mocked up a workbook to use this code before I posted it here and it worked.
 
Upvote 0
1004 just means your trying to do something with a reference that isn't cannected to anything. I need to know where it stops in your code, so could you please run your code again and when it stops click debug, you'll see the line in yellow. I mocked up a workbook to use this code before I posted it here and it worked.
Sorry, I think I didn’t asked the right question earlier.

So, I created a Formulae driven excel workbook consisting of 3 sheets.
- I want to create a macro with export button that will help me to copy the data from Range A1 to D600 in sheet 3.
-I want to paste that data from Sheet 3 into a new CSV excel file that is saved in my Downloads folder in my PC

Can you help me to code this?

One of my friend gave me below mentioned code, but It giving error at the bold text below

Application.ScreenUpdating - False
Dim FPath As String, Inventory As Workbook, SE As Worksheet
FPath = " where ever"
Workbooks .Open FPath & "Report.csv”
Set SE
= ThisWorkbook. Sheets ("SE")
Set report = Workbooks ("Report.csv")
SUE.Range ("$A$1: $D$600").Copy
Report.Sheets (1) .Range ("Al"). PasteSpecial Paste: =xlPasteValues
stripe. Close SaveChanges:=True
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,712
Members
449,093
Latest member
Mnur

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