View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
uriel78 uriel78 is offline
external usenet poster
 
Posts: 38
Default another little question...

thank you, I forgot to say I wish I could use the

FName = Application.GetOpenFilename

instead of dir (that, as I can see, selects every file)

to select the files (as in every directory there are also other *.xls file
whose columns haven't to be imported and I can't move those files form dir,
too)






"Ron de Bruin" ha scritto nel messaggio
...

Hi uriel78

Use Dir for this.
Easier, Copy the code in a workbook outside the folder C:\Data.
It will use the first sheet of this workbook

Change

For Each sh In mybook.Sheets(Array("Sheet1", "Sheet3"))

MyPath = "C:\Data"




Sub Tester()
Dim basebook As Workbook
Dim mybook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim Colnum As Long
Dim SourceCcount As Long
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String
Dim sh As Worksheet

SaveDriveDir = CurDir
MyPath = "C:\Data"
ChDrive MyPath
ChDir MyPath
FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

Application.ScreenUpdating = False
Set basebook = ThisWorkbook
basebook.Worksheets(1).Cells.Clear
'clear all cells on the first sheet
Colnum = 1

Do While FNames < ""
Set mybook = Workbooks.Open(FNames)
For Each sh In mybook.Sheets(Array("Sheet1", "Sheet3"))
Set sourceRange = sh.Columns("I:J")
SourceCcount = sourceRange.Columns.Count
Set destrange = basebook.Worksheets(1).Columns(Colnum)

sourceRange.Copy destrange
Colnum = Colnum + SourceCcount
Next sh
mybook.Close False
FNames = Dir()
Loop
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub




--
Regards Ron de Bruin
http://www.rondebruin.nl



"uriel78" wrote in message

...
Just another little question,
If I want to import data from 4 sheets (by specifying their names) (not
every sheet) how can I modify the macro...?

I don't know how...I suppose I've to change sthg in

GetData FName(N), "sheet1", "I:J", destrange, False


I need to import columns I:J from 4 worksheets for each workbook....can

you
help me...?