Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic data type for columns

Status
Not open for further replies.

meldrape

Programmer
May 12, 2001
516
US
Hello there,

I recorded a macro to import some data into excel from a text file. I had to set each column as text datatype. Is there a way I can make it dynamic so I can use this module for other imports? Here's the line that sets the datatype:
Code:
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, _
        2, 2)
Is there any way I can make that a dynamic array or a dynamic datatype for the entire import? Thank you in advance.
 
You could try making it Variant.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Many thanks for your speedy reply. Please excuse my ignorance (or not) and I probably didn't explain it properly but what exactly do you mean? Some of the imports might have 30 columns, some might have 7. What I am looking for is a way to set the array for any number of columns, instead of 2,2,2,2,2 etc. I don't use excel very often so I need all the help I can get :)

Thanks again!!
 
Aah, I think I understand. So the number of fields in the text file will be variable?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I would simply create a temp array, dim it to the number of fields in the text file. Do a for loop from lbound of the array to ubound of the array setting each value to be what you want as you go. Then do the .TextFileColumnDataTypes assignment.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks Tom. I might need help with syntax but I"ll give it a shot. THanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top