Copy rows from other Excel-file

M

maywood

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top