ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Import CSV with match (https://www.excelbanter.com/excel-programming/300562-import-csv-match.html)

Scottz

Import CSV with match
 
Hello all,

Apologize if this is in the wrong group.

I'm trying to create a VBA macro (Excel 2003) to import a CSV file,
match the first field in the CSV file to a matching cell in th
worksheet (column b), and import the rest of the csv data starting a
colomn c.

Ultimatly I would like to automate the process using templates to buil
up a workbook with several sheets that import data like this.

I've tried searching for examples or other ideas on this but haven'
had much luck so far.

Any help would be appreciated.

Many Thanks,
Scott

--
Message posted from http://www.ExcelForum.com


Trevor Shuttleworth

Import CSV with match
 
Scottz

one way would be to use Input # to read the CSV file and process the records
one by one. This could be slow unless there are only a relatively small
number of records. See the Help file for Input.

Personally, I'd just import the entire file and then process the records
depending on the value in the first row, modified by the (V)LOOKUP into the
other worksheet.

Another option is to use Data | Get external data | Import text file to get
the data into a worksheet and then process it.

You could always create a temporary sheet, import the data, massage it, move
it and then delete the temporary sheet.

Regards

Trevor


"Scottz " wrote in message
...
Hello all,

Apologize if this is in the wrong group.

I'm trying to create a VBA macro (Excel 2003) to import a CSV file,
match the first field in the CSV file to a matching cell in the
worksheet (column b), and import the rest of the csv data starting at
colomn c.

Ultimatly I would like to automate the process using templates to build
up a workbook with several sheets that import data like this.

I've tried searching for examples or other ideas on this but haven't
had much luck so far.

Any help would be appreciated.

Many Thanks,
Scottz


---
Message posted from http://www.ExcelForum.com/




Scottz[_2_]

Import CSV with match
 
It is a small amount of data, and the input method would work.

However I don't know how to perform the match in the worksheet with th
csv data.

I can't seem to figure out how to do a match or vlookup on th
worksheet from within VBA (sorry, new to this aspect of vb).

Or do I have to manually loop through each cell in the column to fin
the match??

Thanks,
-Scot

--
Message posted from http://www.ExcelForum.com


Trevor Shuttleworth

Import CSV with match
 
Scott

a very brief example:

Sub ExampleLookup()
Dim myVariable As String ' define a string variable
myVariable = "JJ" ' give the variable a value
' use MsgBox to display the fifth element
' from the table in columns A to E
MsgBox _
Application.WorksheetFunction.VLookup( _
myVariable, Range("A:E"), 5, False)
End Sub

Regards

Trevor


"Scottz " wrote in message
...
It is a small amount of data, and the input method would work.

However I don't know how to perform the match in the worksheet with the
csv data.

I can't seem to figure out how to do a match or vlookup on the
worksheet from within VBA (sorry, new to this aspect of vb).

Or do I have to manually loop through each cell in the column to find
the match??

Thanks,
-Scott


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 12:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com