Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
D
 
Posts: n/a
Default Easiest Way to do this Importing method?

Hey guys- been searching for a while now, and all the posts are a little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another 'Template'
file. But- here's the key- not EVERY column in the CSV file needs to import
into my template. Also, the columns in the CSV file are NOT in the same
order they need to be in the Template file. So, I need to be able to pick
and choose which columns import and go where. Does that make sense? Is there
an easy 'import mapping' system to use or any other way to do this? Like I
said, everything Im seeing is looking pretty complicated- more than I think
it needs to be. This seems as if it'd be fairly easy to accomplish, I'm just
not finding answers I need.
Thanks for any help.
D


  #2   Report Post  
Earl Kiosterud
 
Posts: n/a
Default

D,

No mapping that I know of -- but easily done with macro programming. There
are multiple ways to read a text file into a sheet, depending in part on the
version of Excel you're using. Check out
http://www.smokeylake.com/excel/textfiles.htm

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"D" wrote in message news:HdXjd.244895$a85.37719@fed1read04...
Hey guys- been searching for a while now, and all the posts are a little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another 'Template'
file. But- here's the key- not EVERY column in the CSV file needs to
import into my template. Also, the columns in the CSV file are NOT in the
same order they need to be in the Template file. So, I need to be able to
pick and choose which columns import and go where. Does that make sense?
Is there an easy 'import mapping' system to use or any other way to do
this? Like I said, everything Im seeing is looking pretty complicated-
more than I think it needs to be. This seems as if it'd be fairly easy to
accomplish, I'm just not finding answers I need.
Thanks for any help.
D



  #3   Report Post  
D
 
Posts: n/a
Default

Hmmm- not sure about this. Someone was telling me about 'linking' files or
columns from one sheet to another. Is this easily done and can work in my
situation? How do I do it if it can work?
thanks
D


"Earl Kiosterud" wrote in message
...
D,

No mapping that I know of -- but easily done with macro programming.
There are multiple ways to read a text file into a sheet, depending in
part on the version of Excel you're using. Check out
http://www.smokeylake.com/excel/textfiles.htm

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"D" wrote in message news:HdXjd.244895$a85.37719@fed1read04...
Hey guys- been searching for a while now, and all the posts are a little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another
'Template' file. But- here's the key- not EVERY column in the CSV file
needs to import into my template. Also, the columns in the CSV file are
NOT in the same order they need to be in the Template file. So, I need to
be able to pick and choose which columns import and go where. Does that
make sense? Is there an easy 'import mapping' system to use or any other
way to do this? Like I said, everything Im seeing is looking pretty
complicated- more than I think it needs to be. This seems as if it'd be
fairly easy to accomplish, I'm just not finding answers I need.
Thanks for any help.
D





  #4   Report Post  
NickHK
 
Posts: n/a
Default

D,
You could query the text file then.
Check out Dataget External dataNew database query and tailor to your needs
for the text file.

NickHK

"D" wrote in message news:MBXjd.245050$a85.38010@fed1read04...
Hmmm- not sure about this. Someone was telling me about 'linking' files or
columns from one sheet to another. Is this easily done and can work in my
situation? How do I do it if it can work?
thanks
D


"Earl Kiosterud" wrote in message
...
D,

No mapping that I know of -- but easily done with macro programming.
There are multiple ways to read a text file into a sheet, depending in
part on the version of Excel you're using. Check out
http://www.smokeylake.com/excel/textfiles.htm

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"D" wrote in message news:HdXjd.244895$a85.37719@fed1read04...
Hey guys- been searching for a while now, and all the posts are a

little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another
'Template' file. But- here's the key- not EVERY column in the CSV file
needs to import into my template. Also, the columns in the CSV file are
NOT in the same order they need to be in the Template file. So, I need

to
be able to pick and choose which columns import and go where. Does that
make sense? Is there an easy 'import mapping' system to use or any

other
way to do this? Like I said, everything Im seeing is looking pretty
complicated- more than I think it needs to be. This seems as if it'd be
fairly easy to accomplish, I'm just not finding answers I need.
Thanks for any help.
D







  #5   Report Post  
D
 
Posts: n/a
Default

ok, this may sound silly here, but-
The CSV file isn't a text file per se', it's an Excel CSV file. Does that
matter? I am checking that out now- thanks Nick.
D


"NickHK" wrote in message
...
D,
You could query the text file then.
Check out Dataget External dataNew database query and tailor to your
needs
for the text file.

NickHK

"D" wrote in message news:MBXjd.245050$a85.38010@fed1read04...
Hmmm- not sure about this. Someone was telling me about 'linking' files
or
columns from one sheet to another. Is this easily done and can work in my
situation? How do I do it if it can work?
thanks
D


"Earl Kiosterud" wrote in message
...
D,

No mapping that I know of -- but easily done with macro programming.
There are multiple ways to read a text file into a sheet, depending in
part on the version of Excel you're using. Check out
http://www.smokeylake.com/excel/textfiles.htm

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"D" wrote in message
news:HdXjd.244895$a85.37719@fed1read04...
Hey guys- been searching for a while now, and all the posts are a

little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another
'Template' file. But- here's the key- not EVERY column in the CSV file
needs to import into my template. Also, the columns in the CSV file
are
NOT in the same order they need to be in the Template file. So, I need

to
be able to pick and choose which columns import and go where. Does
that
make sense? Is there an easy 'import mapping' system to use or any

other
way to do this? Like I said, everything Im seeing is looking pretty
complicated- more than I think it needs to be. This seems as if it'd
be
fairly easy to accomplish, I'm just not finding answers I need.
Thanks for any help.
D











  #6   Report Post  
NickHK
 
Posts: n/a
Default

D,
It's still text, just indicating that it is Comma Separated.

Alternative way is DataImport Text file, select which columns to drop, then
rearrange your columns in the required order.

NickHK

"D" wrote in message news:naYjd.245283$a85.49229@fed1read04...
ok, this may sound silly here, but-
The CSV file isn't a text file per se', it's an Excel CSV file. Does that
matter? I am checking that out now- thanks Nick.
D


"NickHK" wrote in message
...
D,
You could query the text file then.
Check out Dataget External dataNew database query and tailor to your
needs
for the text file.

NickHK

"D" wrote in message news:MBXjd.245050$a85.38010@fed1read04...
Hmmm- not sure about this. Someone was telling me about 'linking' files
or
columns from one sheet to another. Is this easily done and can work in

my
situation? How do I do it if it can work?
thanks
D


"Earl Kiosterud" wrote in message
...
D,

No mapping that I know of -- but easily done with macro programming.
There are multiple ways to read a text file into a sheet, depending

in
part on the version of Excel you're using. Check out
http://www.smokeylake.com/excel/textfiles.htm

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"D" wrote in message
news:HdXjd.244895$a85.37719@fed1read04...
Hey guys- been searching for a while now, and all the posts are a

little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another
'Template' file. But- here's the key- not EVERY column in the CSV

file
needs to import into my template. Also, the columns in the CSV file
are
NOT in the same order they need to be in the Template file. So, I

need
to
be able to pick and choose which columns import and go where. Does
that
make sense? Is there an easy 'import mapping' system to use or any

other
way to do this? Like I said, everything Im seeing is looking pretty
complicated- more than I think it needs to be. This seems as if it'd
be
fairly easy to accomplish, I'm just not finding answers I need.
Thanks for any help.
D











  #7   Report Post  
D
 
Posts: n/a
Default

Hmmm- I dont see that option. I go to DataImport I select my file, select
my sheet, and then it imports the ENTIRE sheet into the file, not give me
the options as to which columns I want where. Any ideas? What am I missing?
Thanks
D



"NickHK" wrote in message
...
D,
It's still text, just indicating that it is Comma Separated.

Alternative way is DataImport Text file, select which columns to drop,
then
rearrange your columns in the required order.

NickHK

"D" wrote in message news:naYjd.245283$a85.49229@fed1read04...
ok, this may sound silly here, but-
The CSV file isn't a text file per se', it's an Excel CSV file. Does that
matter? I am checking that out now- thanks Nick.
D


"NickHK" wrote in message
...
D,
You could query the text file then.
Check out Dataget External dataNew database query and tailor to your
needs
for the text file.

NickHK

"D" wrote in message
news:MBXjd.245050$a85.38010@fed1read04...
Hmmm- not sure about this. Someone was telling me about 'linking'
files
or
columns from one sheet to another. Is this easily done and can work in

my
situation? How do I do it if it can work?
thanks
D


"Earl Kiosterud" wrote in message
...
D,

No mapping that I know of -- but easily done with macro programming.
There are multiple ways to read a text file into a sheet, depending

in
part on the version of Excel you're using. Check out
http://www.smokeylake.com/excel/textfiles.htm

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"D" wrote in message
news:HdXjd.244895$a85.37719@fed1read04...
Hey guys- been searching for a while now, and all the posts are a
little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another
'Template' file. But- here's the key- not EVERY column in the CSV

file
needs to import into my template. Also, the columns in the CSV file
are
NOT in the same order they need to be in the Template file. So, I

need
to
be able to pick and choose which columns import and go where. Does
that
make sense? Is there an easy 'import mapping' system to use or any
other
way to do this? Like I said, everything Im seeing is looking pretty
complicated- more than I think it needs to be. This seems as if
it'd
be
fairly easy to accomplish, I'm just not finding answers I need.
Thanks for any help.
D













  #8   Report Post  
Patrik
 
Posts: n/a
Default

"D" wrote in message news:<HdXjd.244895$a85.37719@fed1read04...
Hey guys- been searching for a while now, and all the posts are a little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another 'Template'
file. But- here's the key- not EVERY column in the CSV file needs to import
into my template. Also, the columns in the CSV file are NOT in the same
order they need to be in the Template file. So, I need to be able to pick
and choose which columns import and go where. Does that make sense? Is there
an easy 'import mapping' system to use or any other way to do this? Like I
said, everything Im seeing is looking pretty complicated- more than I think
it needs to be. This seems as if it'd be fairly easy to accomplish, I'm just
not finding answers I need.
Thanks for any help.
D


Hello
Well I like programming/VBA approaches because its quick and gives you
good control. I dont know if there is any "Import wizard" that can do
this. To write code that does what you want is not very difficult.
A suggestion would be to read all of the CSV-file into an array and go
from there. It is easier and more effective to manupulate data "In
memory".
Something like this:
Function CSVFileToArray(inFile As String) As Variant
Dim fileHandle As Integer
Dim i As Integer
Dim outArray() As String
Dim tempStr As String
If Dir(inFile) = "" Then 'Check if the file exists
Msgbox "CSVFileToArray: Could not find/open " & inFile
Exit Function
End If
fileHandle = FreeFile()
Open inFile For Input As #fileHandle
i = 0
Do While Not EOF(fileHandle) ' Loop until end of file.
On Error Resume Next
Input #fileHandle, tempStr
On Error GoTo 0
If tempStr < "" And InStr(",", tempStr) = 0 Then
ReDim Preserve outArray(i)
outArray(i) = tempStr
i = i + 1
End If
Loop
Close #fileHandle
CSVFileToArray = outArray
End Function

Then you can describe what you want from the file in another array
that you initialize early on. Here is an example function from a
program I've done:

Type tFieldDesc
sFieldName As String
iColPos As Integer
bConvert As Boolean
bDate As Boolean
End Type

Function CreateFieldDescrArray() As tFieldDesc()
Static bIsInitialized As Boolean
Static arrFieldDesc(FIELD_DESC_ARRAY_UBOUND) As tFieldDesc
'CAUTION the global constant FIELD_DESC_ARRAY_UBOUND must be set to
'the number of field descriptions minus one!

'An array that contains descriptions of fields
'0 = The name of the field
'1 = The column position
'2 = Does the field need conversion
'3 = Is it a date field
If Not bIsInitialized Then
Dim arrTmp, vElement
arrTmp = Array( _
Array("Provid", "1", "", ""), Array("Status", "2", "Y", ""), _
Array("UPPDRAG", "6", "", ""), Array("Header", "7", "", ""), _
Array("Bestnamn", "8", "", ""), Array("BestAvd", "9", "", ""), _
Array("Memoid", "10", "", ""), Array("UtfAvd", "11", "", ""), _
Array("StartW", "12", "", "Y"), Array("EndW", "13", "", "Y"), _

Dim i As Integer
i = 0
For Each vElement In arrTmp
arrFieldDesc(i).sFieldName = vElement(0)
arrFieldDesc(i).iColPos = CInt(vElement(1))
arrFieldDesc(i).bConvert = False
If vElement(2) < "" Then
arrFieldDesc(i).bConvert = True
End If
arrFieldDesc(i).bDate = False
If vElement(3) < "" Then
arrFieldDesc(i).bDate = True
End If
i = i + 1
Next
bIsInitialized = True
End If
CreateFieldDescrArray = arrFieldDesc
End Function

Then you write the main data crunching Sub. Something like this:

Sub GetTheData()
arrFieldDescr = CreateFieldDescrArray()
arrTheWholeFile = CSVFileToArray("C:\Datafile.csv")

j = 0
k = 0
For i = 0 to Ubound(arrTheWholeFile)
If j Mod NUMBER_OF_COLUMNS = 0 Then
'NUMBER_OF_COLUMNS is a constant that has the number of columns
in the
'CSVfile you wish to process
j = 0
else
j = j + 1
end if
sResult = GetElement(arrFieldDescr, arrTheWholeFile(i), j)
if sResult < "" then
arrResult(k) = sResult
k = k + 1
end if
next
end sub

Function GetElement(arrFieldDescr, sElement, j) as string
GetElement = ""
For each item in arrFieldDescr
if item.iColPos = j then
GetElement = sElement
break
end if
next
end function


This was a very quick repsonse just to get you started along the way I
would reccomend. All variables should be declared of course.

Regards /Patrik
  #9   Report Post  
Tom Ogilvy
 
Posts: n/a
Default

After you get it in, you can use code to rearrange and delete columns.

Most of the code can be done by turning the macro recorder on and doing it
manually, then altering the recorded code if necessary.

--
Regards,
Tom Ogilvy

"D" wrote in message news:MZYjd.245347$a85.189457@fed1read04...
Hmmm- I dont see that option. I go to DataImport I select my file,

select
my sheet, and then it imports the ENTIRE sheet into the file, not give me
the options as to which columns I want where. Any ideas? What am I

missing?
Thanks
D



"NickHK" wrote in message
...
D,
It's still text, just indicating that it is Comma Separated.

Alternative way is DataImport Text file, select which columns to drop,
then
rearrange your columns in the required order.

NickHK

"D" wrote in message news:naYjd.245283$a85.49229@fed1read04...
ok, this may sound silly here, but-
The CSV file isn't a text file per se', it's an Excel CSV file. Does

that
matter? I am checking that out now- thanks Nick.
D


"NickHK" wrote in message
...
D,
You could query the text file then.
Check out Dataget External dataNew database query and tailor to

your
needs
for the text file.

NickHK

"D" wrote in message
news:MBXjd.245050$a85.38010@fed1read04...
Hmmm- not sure about this. Someone was telling me about 'linking'
files
or
columns from one sheet to another. Is this easily done and can work

in
my
situation? How do I do it if it can work?
thanks
D


"Earl Kiosterud" wrote in message
...
D,

No mapping that I know of -- but easily done with macro

programming.
There are multiple ways to read a text file into a sheet,

depending
in
part on the version of Excel you're using. Check out
http://www.smokeylake.com/excel/textfiles.htm

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"D" wrote in message
news:HdXjd.244895$a85.37719@fed1read04...
Hey guys- been searching for a while now, and all the posts are a
little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another
'Template' file. But- here's the key- not EVERY column in the CSV

file
needs to import into my template. Also, the columns in the CSV

file
are
NOT in the same order they need to be in the Template file. So, I

need
to
be able to pick and choose which columns import and go where.

Does
that
make sense? Is there an easy 'import mapping' system to use or

any
other
way to do this? Like I said, everything Im seeing is looking

pretty
complicated- more than I think it needs to be. This seems as if
it'd
be
fairly easy to accomplish, I'm just not finding answers I need.
Thanks for any help.
D















  #10   Report Post  
Gary Rowe
 
Posts: n/a
Default

Select data/import external data/new database query. Select your datasource
or create a new one using the Microsoft text driver. Uncheck the use query
wizard and complete the process. In MSQuery select the columns in whatever
order you want and return to excel.

"D" wrote:

Hey guys- been searching for a while now, and all the posts are a little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another 'Template'
file. But- here's the key- not EVERY column in the CSV file needs to import
into my template. Also, the columns in the CSV file are NOT in the same
order they need to be in the Template file. So, I need to be able to pick
and choose which columns import and go where. Does that make sense? Is there
an easy 'import mapping' system to use or any other way to do this? Like I
said, everything Im seeing is looking pretty complicated- more than I think
it needs to be. This seems as if it'd be fairly easy to accomplish, I'm just
not finding answers I need.
Thanks for any help.
D





  #11   Report Post  
Electra
 
Posts: n/a
Default

Hi D,
the simple answer is that there is no easy way to do this. But with
some effort Excel will allow you to do this. Programming/formulas
will be required. I am not sure if you still want to do it? But
below is 1 way to do it.

To import this file into Excel it matters which version of Excel you
are using. The way to do this varies depending on the version of
Excel you are working in. I am working in Excel 2003.

in this version of excel choose:
dataimport external dataimport datafiles of type: all file browse
to your cvs file. click on it and choose open.

when you do that the import wizard opens and you are on step 1 of 3 in
the import wizard screens. on screen 1 choose delimited file and
click next

on the step 2 of 3 screens in the import wizard choose:
delimiters: commas(deselect others)
also check: treat consective delimiters as 1
and choose text qualifiers: none
click next

on the step 3 of 3 screens in the import wizard HIGHLIGHT EACH COLUMN
YOU DON'T WANT imported AND CHOOSE the Column data format radio button
at the bottom do not import column(skip) when done click finished

on the next screen (import data screen) select the New worksheet radio
button
(note the properites button at bottom: you can change some properities
but if you are a novice user just leave it) click ok and you are done.

The next time you want to read this data into excel just click
datarefresh data (at the bottom). Note the file has to have the
exact same structure the next time. More rows are ok but more
columns(commas) are not.

Now moving the columns around. it is best not to move the columns
around on this sheet because when you refesh the sheet all those
changes will be wiped out.

I think a better idea is to make another sheet in the same workbook
and set up formula that rearrange the sheets. For example if sheet2
is the import sheet then on sheet1 in cell a1 you could type
=sheet2!c1 and copy this formula down. that would mmove column C to
Colunm A


"D" wrote in message news:<MZYjd.245347$a85.189457@fed1read04...
Hmmm- I dont see that option. I go to DataImport I select my file, select
my sheet, and then it imports the ENTIRE sheet into the file, not give me
the options as to which columns I want where. Any ideas? What am I missing?
Thanks
D



"NickHK" wrote in message
...
D,
It's still text, just indicating that it is Comma Separated.

Alternative way is DataImport Text file, select which columns to drop,
then
rearrange your columns in the required order.

NickHK

"D" wrote in message news:naYjd.245283$a85.49229@fed1read04...
ok, this may sound silly here, but-
The CSV file isn't a text file per se', it's an Excel CSV file. Does that
matter? I am checking that out now- thanks Nick.
D


"NickHK" wrote in message
...
D,
You could query the text file then.
Check out Dataget External dataNew database query and tailor to your
needs
for the text file.

NickHK

"D" wrote in message
news:MBXjd.245050$a85.38010@fed1read04...
Hmmm- not sure about this. Someone was telling me about 'linking'
files
or
columns from one sheet to another. Is this easily done and can work in

my
situation? How do I do it if it can work?
thanks
D


"Earl Kiosterud" wrote in message
...
D,

No mapping that I know of -- but easily done with macro programming.
There are multiple ways to read a text file into a sheet, depending

in
part on the version of Excel you're using. Check out
http://www.smokeylake.com/excel/textfiles.htm

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"D" wrote in message
news:HdXjd.244895$a85.37719@fed1read04...
Hey guys- been searching for a while now, and all the posts are a

little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another
'Template' file. But- here's the key- not EVERY column in the CSV

file
needs to import into my template. Also, the columns in the CSV file
are
NOT in the same order they need to be in the Template file. So, I

need
to
be able to pick and choose which columns import and go where. Does
that
make sense? Is there an easy 'import mapping' system to use or any

other
way to do this? Like I said, everything Im seeing is looking pretty
complicated- more than I think it needs to be. This seems as if
it'd
be
fairly easy to accomplish, I'm just not finding answers I need.
Thanks for any help.
D











  #12   Report Post  
D
 
Posts: n/a
Default

FYI-
Found the easiest way to do this is via linking the cells. I hi-light a
column of info from the CSV file, then paste it on another sheet in the
column I want it to go. Then I click the little clip board and select link
cells. And then I use this whole file as a template for all my work. Then
just save as when I'm done. Fastest, easiest way to do it.
Thanks!
D



"Patrik" wrote in message
m...
"D" wrote in message news:<HdXjd.244895$a85.37719@fed1read04...
Hey guys- been searching for a while now, and all the posts are a little
more complex than I think this needs to be. Can you help?

Basically, I have a CSV file that I need to import into another
'Template'
file. But- here's the key- not EVERY column in the CSV file needs to
import
into my template. Also, the columns in the CSV file are NOT in the same
order they need to be in the Template file. So, I need to be able to pick
and choose which columns import and go where. Does that make sense? Is
there
an easy 'import mapping' system to use or any other way to do this? Like
I
said, everything Im seeing is looking pretty complicated- more than I
think
it needs to be. This seems as if it'd be fairly easy to accomplish, I'm
just
not finding answers I need.
Thanks for any help.
D


Hello
Well I like programming/VBA approaches because its quick and gives you
good control. I dont know if there is any "Import wizard" that can do
this. To write code that does what you want is not very difficult.
A suggestion would be to read all of the CSV-file into an array and go
from there. It is easier and more effective to manupulate data "In
memory".
Something like this:
Function CSVFileToArray(inFile As String) As Variant
Dim fileHandle As Integer
Dim i As Integer
Dim outArray() As String
Dim tempStr As String
If Dir(inFile) = "" Then 'Check if the file exists
Msgbox "CSVFileToArray: Could not find/open " & inFile
Exit Function
End If
fileHandle = FreeFile()
Open inFile For Input As #fileHandle
i = 0
Do While Not EOF(fileHandle) ' Loop until end of file.
On Error Resume Next
Input #fileHandle, tempStr
On Error GoTo 0
If tempStr < "" And InStr(",", tempStr) = 0 Then
ReDim Preserve outArray(i)
outArray(i) = tempStr
i = i + 1
End If
Loop
Close #fileHandle
CSVFileToArray = outArray
End Function

Then you can describe what you want from the file in another array
that you initialize early on. Here is an example function from a
program I've done:

Type tFieldDesc
sFieldName As String
iColPos As Integer
bConvert As Boolean
bDate As Boolean
End Type

Function CreateFieldDescrArray() As tFieldDesc()
Static bIsInitialized As Boolean
Static arrFieldDesc(FIELD_DESC_ARRAY_UBOUND) As tFieldDesc
'CAUTION the global constant FIELD_DESC_ARRAY_UBOUND must be set to
'the number of field descriptions minus one!

'An array that contains descriptions of fields
'0 = The name of the field
'1 = The column position
'2 = Does the field need conversion
'3 = Is it a date field
If Not bIsInitialized Then
Dim arrTmp, vElement
arrTmp = Array( _
Array("Provid", "1", "", ""), Array("Status", "2", "Y", ""), _
Array("UPPDRAG", "6", "", ""), Array("Header", "7", "", ""), _
Array("Bestnamn", "8", "", ""), Array("BestAvd", "9", "", ""), _
Array("Memoid", "10", "", ""), Array("UtfAvd", "11", "", ""), _
Array("StartW", "12", "", "Y"), Array("EndW", "13", "", "Y"), _

Dim i As Integer
i = 0
For Each vElement In arrTmp
arrFieldDesc(i).sFieldName = vElement(0)
arrFieldDesc(i).iColPos = CInt(vElement(1))
arrFieldDesc(i).bConvert = False
If vElement(2) < "" Then
arrFieldDesc(i).bConvert = True
End If
arrFieldDesc(i).bDate = False
If vElement(3) < "" Then
arrFieldDesc(i).bDate = True
End If
i = i + 1
Next
bIsInitialized = True
End If
CreateFieldDescrArray = arrFieldDesc
End Function

Then you write the main data crunching Sub. Something like this:

Sub GetTheData()
arrFieldDescr = CreateFieldDescrArray()
arrTheWholeFile = CSVFileToArray("C:\Datafile.csv")

j = 0
k = 0
For i = 0 to Ubound(arrTheWholeFile)
If j Mod NUMBER_OF_COLUMNS = 0 Then
'NUMBER_OF_COLUMNS is a constant that has the number of columns
in the
'CSVfile you wish to process
j = 0
else
j = j + 1
end if
sResult = GetElement(arrFieldDescr, arrTheWholeFile(i), j)
if sResult < "" then
arrResult(k) = sResult
k = k + 1
end if
next
end sub

Function GetElement(arrFieldDescr, sElement, j) as string
GetElement = ""
For each item in arrFieldDescr
if item.iColPos = j then
GetElement = sElement
break
end if
next
end function


This was a very quick repsonse just to get you started along the way I
would reccomend. All variables should be declared of course.

Regards /Patrik



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
Importing MM:SS From Tab Delimited File and Charting Bryan Charts and Charting in Excel 4 July 28th 06 04:14 PM
importing multiple text files??? tashayu Excel Discussion (Misc queries) 0 December 19th 04 02:43 PM
Method to increment value in data field? Karl H Excel Discussion (Misc queries) 1 December 4th 04 07:31 PM
Importing XML data from http request Pau Larsen Excel Discussion (Misc queries) 0 December 2nd 04 02:01 PM
Importing Question! Otto Moehrbach Excel Discussion (Misc queries) 0 November 26th 04 07:04 PM


All times are GMT +1. The time now is 08: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"