LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Import csv files, delete rows, arrange columns ....

I am importing 34 csv files (each into a different sheet) into one workbook
with one "Main" sheet. e.g. "Main", "1", "2", ..... , "34". Once these are
imported, I have to delete unwanted data from certain columns. Then organize
the columns to a specific order to match the "Main" sheet. The column
heading is located in range("A16:AF16") on the csv imported tabs. Once it is
arranged in this format, I have to find the max and min of certain columns
and select that corresponding row of data to copy to the "main" sheet. I
just need help getting started with the sorting process. This is what I have
so far. TIA for any help you can provide.

Sub OpenCSVFiles()
Dim wks As Worksheet
Dim wkbk As Workbook
Dim rngchan As Range
Dim wksmain As Worksheet
Dim i As Integer

Set wksmain = Sheets("Main")

With Application.FileSearch
.NewSearch
.LookIn = "C:\test\csv"
.SearchSubFolders = False
.Filename = ".csv"
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
Set wkbk = Workbooks.Open(Filename:=.FoundFiles(i))

For Each wks In wkbk.Worksheets
dblLastRow = Range("A65535").End(xlUp).Row
Set rngchan = Range("A16:AF16")
wks.Copy after:=ThisWorkbook.Sheets(i) 'Change sheet name

Range("a1,b1,c1,d1,e1,h1,j1,m1,n1,v1:x1,z1,aa1:ad1 ,ai1,al1:aq1,ax1:ba1").EntireColumn.Delete

This is where I need to arrange columns in a certain order from the column
heading in rngchan. In the "main" sheet it is in a certain order. e.g.main
sheet 1,2,3,...34 and on csv tabs it is in 16,3,9,...2

Then I have to find max and min of column 3 and then copy those rows of data
to the "main" sheet in a specified location.



Next wks
wkbk.Close
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

 
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
how do I import .txt file as rows not columns? Phil Zack Excel Discussion (Misc queries) 9 April 3rd 23 01:17 PM
Arrange data spanning 8 columns and 3 rows to 24 columns and 1 row pfdino Excel Discussion (Misc queries) 2 March 19th 07 09:03 PM
import data in rows instead of columns Karen Excel Worksheet Functions 1 August 31st 06 11:24 PM
Import 2 text files into 2 separate columns? tcurrier Excel Discussion (Misc queries) 3 February 11th 06 07:13 PM
import simple data & re-arrange it JohnB[_3_] Excel Programming 5 October 21st 04 01:11 AM


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