View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
maywood maywood is offline
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