Link to home
Start Free TrialLog in
Avatar of finnstone
finnstone

asked on

how to move column in excel - across 8k files

i have 8k csv files in a folder. i would like to move column c to column a position.

any idea how i can do that automatically?
ASKER CERTIFIED SOLUTION
Avatar of Flyster
Flyster
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of finnstone
finnstone

ASKER

Hi Flyster. thanks. However, I ran the code and nothing happens?
On the line that starts "strPath =" did you set the correct path to your files? I tried it with a folder containing 3 workbooks and it changed all 3.
yes i used this

 strPath = "F:\tweet\csvtest"
Did you try my code?
Also, for Flyster's code, I think:
strSearch = Dir(strPath & strFile & "*.csv")

...should be:
strSearch = Dir(strPath & "*.csv")

He's also defining a subroutine, but there's no code in there to actually call it, so if you haven't called the sub, then it won't run.
yes i need to run this for thousands of files so could not use yours.

i insert module and then run macro...but nothing happens
i was missing the \
thank you
yes i need to run this for thousands of files so could not use yours.
You probably should have mentioned that that's what you thought.

My code was a function that could be run on any number of files. I provided an example of it on one file just for example purposes, but it was something that could be run on many, many files. You simply loop through the folder with PHP and run that function on each file:

$csvFiles = glob("*.csv");
foreach($csvFiles as $csvFile)
{
   MoveColumnToBeginning($csvFile, 2);
}

Open in new window


I figured you just wanted the "guts" of the code, which was the MoveColumnToBeginning function.
For what it's worth, if you have to do this on a continual basis, the PHP method should be much faster than an Excel subroutine.
not on a file by file basis its not but hanks anyways
Thanks. Just so you know, you can use the line "strFile = "*" " to filter out a specific file, or all files that start with the same string. Example, if you had files named red1, red2, red3, blue1, blue2, blue3, you could enter strFile = "Red*" and just the files that start with red will update. It adds a little more flexibility to the code.
hi flyster i just opened a similar question, appreciate your help!!