Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default macro to browse for workbook, pick up data and looping

I've got several workbooks; in each workbook there are 4 sheets whose name
is the same for ale the workbooks (call'em sheet1,2,3,4).
In each sheets there are equally organized data (only values change form one
sheet to another)

In a new workbook ("summary") I wish I could have a macro that ask me to
choose a workbook (maybe without opening it), pick up and copy data in
sheet1 and paste in summary workbook. After doing this operation, I'd qant
to be prompt if select another file to do the same operation (choose
workbook, sheet, data ,copy& paste)...

Is it possible...?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default macro to browse for workbook, pick up data and looping

application.GetOpenfileName

provides the file open dialog to select a file.

it returns a fully qualified file name which can be used to open the file
and copy the data.

You can put this in a loop and when the user clicks cancel, you can stop the
loop
--
Regards,
Tom Ogilvy


"uriel78" wrote in message
...
I've got several workbooks; in each workbook there are 4 sheets whose name
is the same for ale the workbooks (call'em sheet1,2,3,4).
In each sheets there are equally organized data (only values change form

one
sheet to another)

In a new workbook ("summary") I wish I could have a macro that ask me to
choose a workbook (maybe without opening it), pick up and copy data in
sheet1 and paste in summary workbook. After doing this operation, I'd qant
to be prompt if select another file to do the same operation (choose
workbook, sheet, data ,copy& paste)...

Is it possible...?





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default macro to browse for workbook, pick up data and looping

This is a start
http://www.rondebruin.nl/summary2.htm

If you need more help post back

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



"uriel78" wrote in message ...
I've got several workbooks; in each workbook there are 4 sheets whose name
is the same for ale the workbooks (call'em sheet1,2,3,4).
In each sheets there are equally organized data (only values change form one
sheet to another)

In a new workbook ("summary") I wish I could have a macro that ask me to
choose a workbook (maybe without opening it), pick up and copy data in
sheet1 and paste in summary workbook. After doing this operation, I'd qant
to be prompt if select another file to do the same operation (choose
workbook, sheet, data ,copy& paste)...

Is it possible...?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default macro to browse for workbook, pick up data and looping


thanks to both of you I will try with your suggestions :-)


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default macro to browse for workbook, pick up data and looping


Two little questions for you (sorry if the solution is simple but I'm going
to use VBA for only few days...)
COnsidering the procedure describe for "copy a range from a closed workbook"
:

1)How can I use it to copy data from two files (1by1 select) and put the
data form file2 starting in columns C (actully, after choosing file2 data,
they overwrite previous data starting in column A)

2) "Copy a range from all files that you have selected with GetOpenFilename"
: how can I define a procedure to substitute the LastRow function with a
"LastColumn" Function...?

3)Last & least: most of data I need to import in a summmary workbook consist
of two columns of data (X and Ycoordinates), i.e. I:L columns. So, by using
your routines (maybe modified with the tips just asked at point 1 and 2) I
can import I:J columns from different workbooks in columns A:B (for the
first file), D:E for the second file and so on.
How can I do to put in cells A1, D1 (in general, the first cell) the name of
worksheet and workbook the series come from...?

The final result should be sthg as

Column A Column B
Column D Column E
workbook1 - worksheet 1
workbook2 - worksheet 1
X1 Y1
X1 Y1
X2 Y2
X2 Y2

and so on...

I hope you can help me to solve these questions...it will be very important
for me....




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default macro to browse for workbook, pick up data and looping

Sorry, the table posted for example is badly-formatted....:-(




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default macro to browse for workbook, pick up data and looping

to use VBA for only few days...)
You want to much I think<g

Use this code example instead
http://www.rondebruin.nl/copy3.htm#column
You don't have to use function for this

You can use mybook.name to fill a cell with the workbook name

You can use this udf in the range example if you want

Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function

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



"uriel78" wrote in message ...

Two little questions for you (sorry if the solution is simple but I'm going
to use VBA for only few days...)
COnsidering the procedure describe for "copy a range from a closed workbook"
:

1)How can I use it to copy data from two files (1by1 select) and put the
data form file2 starting in columns C (actully, after choosing file2 data,
they overwrite previous data starting in column A)

2) "Copy a range from all files that you have selected with GetOpenFilename"
: how can I define a procedure to substitute the LastRow function with a
"LastColumn" Function...?

3)Last & least: most of data I need to import in a summmary workbook consist
of two columns of data (X and Ycoordinates), i.e. I:L columns. So, by using
your routines (maybe modified with the tips just asked at point 1 and 2) I
can import I:J columns from different workbooks in columns A:B (for the
first file), D:E for the second file and so on.
How can I do to put in cells A1, D1 (in general, the first cell) the name of
worksheet and workbook the series come from...?

The final result should be sthg as

Column A Column B
Column D Column E
workbook1 - worksheet 1
workbook2 - worksheet 1
X1 Y1
X1 Y1
X2 Y2
X2 Y2

and so on...

I hope you can help me to solve these questions...it will be very important
for me....




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default macro to browse for workbook, pick up data and looping

Thank you very much for your kindness and rapidity, I'll try and then tell
you the results!!HAve a good night!!




"Ron de Bruin" ha scritto nel messaggio
...
to use VBA for only few days...)

You want to much I think<g

Use this code example instead
http://www.rondebruin.nl/copy3.htm#column
You don't have to use function for this

You can use mybook.name to fill a cell with the workbook name

You can use this udf in the range example if you want

Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function

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



"uriel78" wrote in message

...

Two little questions for you (sorry if the solution is simple but I'm

going
to use VBA for only few days...)
COnsidering the procedure describe for "copy a range from a closed

workbook"
:

1)How can I use it to copy data from two files (1by1 select) and put the
data form file2 starting in columns C (actully, after choosing file2

data,
they overwrite previous data starting in column A)

2) "Copy a range from all files that you have selected with

GetOpenFilename"
: how can I define a procedure to substitute the LastRow function with a
"LastColumn" Function...?

3)Last & least: most of data I need to import in a summmary workbook

consist
of two columns of data (X and Ycoordinates), i.e. I:L columns. So, by

using
your routines (maybe modified with the tips just asked at point 1 and 2)

I
can import I:J columns from different workbooks in columns A:B (for the
first file), D:E for the second file and so on.
How can I do to put in cells A1, D1 (in general, the first cell) the

name of
worksheet and workbook the series come from...?

The final result should be sthg as

Column A Column B
Column D Column E
workbook1 - worksheet 1
workbook2 - worksheet 1
X1 Y1
X1 Y1
X2 Y2
X2 Y2

and so on...

I hope you can help me to solve these questions...it will be very

important
for me....






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default another little question...

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...?


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default another little question...


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...?






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
macro to browse for workbook, pick up data and looping uriel78 Excel Worksheet Functions 1 March 10th 05 12:37 PM
selecting workbook/worksheet from browse button monika Excel Programming 9 February 8th 04 09:40 AM
Looping Macro to remove data where value is 0 Paul Excel Programming 3 January 10th 04 08:08 AM
macro to pick data Sam Excel Programming 1 December 5th 03 01:22 PM
Looping Through Worksheets In A Workbook Steve[_27_] Excel Programming 3 August 5th 03 03:40 PM


All times are GMT +1. The time now is 05:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"