Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Copy CSV to variables

I have been using Excel VBA to open a CSV file, find the last row, and copy
data to an excel file. Once in the excel file using the .offset, I assign
the cell values to a variable. Now that I have populated variables, I do an
insert query against a SQL table. This works fine, but obviously I need to
streamline the process. I would like to simply copy the values from the CSV
directly into my variables, but not sure how to do it?

Say the CSV file has 3 values separated by commas JIM,SMITH,1012223333 and I
want to copy them to Variables with the names FNAME LNAME PHONE.

Obviously I need to find the last row with data in it, and do a loop.



Thanks for any suggestions.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy CSV to variables

If you values are truly on the last row:

Sub ReadStraightTextFile()
Dim fName As String, lName As String
Dim Phone As String

Open "E:\Data\Testfile.CSV" For Input As #1
Do While Not EOF(1)
Input #1, fName, lName, Phone
Loop
'Close the file
Close #1
MsgBox "fname: " & fName & vbNewLine _
& "Lname: " & lName & vbNewLine _
& "Phone: " & Phone
End Sub

--
Regards,
Tom Ogilvy


"Striker" wrote in message
...
I have been using Excel VBA to open a CSV file, find the last row, and copy
data to an excel file. Once in the excel file using the .offset, I assign
the cell values to a variable. Now that I have populated variables, I do
an insert query against a SQL table. This works fine, but obviously I need
to streamline the process. I would like to simply copy the values from the
CSV directly into my variables, but not sure how to do it?

Say the CSV file has 3 values separated by commas JIM,SMITH,1012223333 and
I want to copy them to Variables with the names FNAME LNAME PHONE.

Obviously I need to find the last row with data in it, and do a loop.



Thanks for any suggestions.




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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
variables april27 Excel Programming 1 June 16th 06 01:15 PM
EXCEL FILE a copy/a copy/a copy ....filename ve New Users to Excel 1 September 29th 05 09:12 PM
How do I copy a range of cells in Excel using variables? Dominic Prince Excel Programming 1 April 11th 05 11:40 PM
Looking up two variables Fish Excel Programming 1 February 11th 05 05:59 PM


All times are GMT +1. The time now is 12:11 PM.

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"