Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Macro to import Data
Hello,
I was looking for some help writing a simple macro. It would import data from a .csv file and write it to my specific cells in my open worksheet. For instance, I would click a button on my spreadsheet and it would then import data from C:\Documents and Settings\Eric\Desktop\Import\info.csv then it would copy the value only from B1 to a named cell "First_Name" the process would look something like this copy B1="First_Name" B2="Last_Name" could anybody help me with this? I usually don't write macros but I have been getting more and more work that involves simple ones like this. Thanks for any help. Eric |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Macro to import Data
On Dec 13, 9:28 am, Eric wrote:
Hello, I was looking for some help writing a simple macro. It would import data from a .csv file and write it to my specific cells in my open worksheet. For instance, I would click a button on my spreadsheet and it would then import data from C:\Documents and Settings\Eric\Desktop\Import\info.csv then it would copy the value only from B1 to a named cell "First_Name" the process would look something like this copy B1="First_Name" B2="Last_Name" could anybody help me with this? I usually don't write macros but I have been getting more and more work that involves simple ones like this. Thanks for any help. Eric Hi Eric, Try the code below. Public Sub ImportData() Dim wkb As Workbook Dim csv As Workbook Dim sData As String Set csv = Workbooks("C:\Documents and Settings\Eric\Desktop\Import \i-nfo.csv") Set wkb = ThisWorkbook 'Destination workbook sData = csv.Sheets("Sheet1").Range("B1:B1") wkb.Sheets("Sheet1").Range("A2:A2").Value = sData 'cell First_name End Sub Repeat for Last_name by defining a Dim statement and last 2 statements Regards trevosef |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro to Open the Menu Data,Refresh Data,filename,import | Excel Programming | |||
Run a macro after data Import | Excel Programming | |||
import data with macro | Excel Discussion (Misc queries) | |||
import simple data & re-arrange it | Excel Programming | |||
Simple macro - show all data | Excel Programming |