Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to Open the Menu Data,Refresh Data,filename,import Bob Excel Programming 0 February 11th 06 04:51 PM
Run a macro after data Import Fred[_24_] Excel Programming 1 July 29th 05 09:30 AM
import data with macro chris_rip Excel Discussion (Misc queries) 0 July 18th 05 08:40 PM
import simple data & re-arrange it JohnB[_3_] Excel Programming 5 October 21st 04 01:11 AM
Simple macro - show all data Neil[_22_] Excel Programming 2 August 10th 04 10:39 AM


All times are GMT +1. The time now is 07:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"