Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Copy rows from other Excel-file

Hi,

In my workbook (NewWkb) I am using a Command Button to import some complete
sheets from another Excel file (ImportWkB) (see code below).
Now I want to use the same button to import additionaly some special rows
from some sheets from a second excel-file (ImportWkB2). Is that possible?

For example I want to copy row 2 & 5 from sheet 2 and row 3 & 6 from sheet 3
in my second excel source-file to my workbook Sheet 11 in cell B10 and below
Does someone has an idea hot wo extend the code?

-----Code-------:
Private Sub CommandButton1_Click()
Dim fname As Variant
Dim NewWkb As Workbook ' destination workbook
Dim ImportWkB As Workbook ' source workbook No1
Dim ImportWkB2 As Workbook ' the second excel source-file
Dim sh As Variant 'sheets
Dim DestRange As Range

Set NewWkb = ThisWorkbook

fname = Application.GetOpenFilename("Excel-Data-Input,*.xls", ,
"Source")
If fname < False Then
Application.ScreenUpdating = False
Set ImportWkB = Workbooks.Open(fname, ReadOnly:=True, UpdateLinks:=0)

For Each sh In ImportWkB.Sheets
NewWkb.Sheets(sh.Index + 4).Cells.UnMerge
Set DestRange = NewWkb.Sheets(sh.Index + 4).Range("B10")
sh.UsedRange.Copy

With DestRange
.PasteSpecial xlPasteValues, , False, False
.PasteSpecial xlPasteFormats, , False, False
End With
Set DestRange = Nothing

Application.CutCopyMode = False

If sh.Index = 6 Then Exit For
Next sh

ImportWkB.Close False
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
copy rows to another file climate Excel Worksheet Functions 3 May 19th 10 10:47 AM
copy rows to another file climate Excel Worksheet Functions 0 May 19th 10 09:04 AM
copy rows to another file climate Excel Worksheet Functions 0 May 19th 10 09:00 AM
Copy Rows From To CSV File Joe K. Excel Programming 1 October 5th 07 05:46 PM
How do i copy a scramble file with 20970 rows to excel? Kim New Users to Excel 4 September 9th 06 02:31 PM


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

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"