PDA

View Full Version : Copy Extenal workbook help



KK1966
06-27-2008, 08:09 AM
Dear Expert’s

Thanks all of your’s help I’m very much here’s, Below the code was learn form the forum to copy external workbook paste in a objects worksheets, Now I has a problem to want some help or learn me how to modify this module to a copy different range in the same worksheets like as,

Opening workbook “ copy to” Active worksheets
Range( C16 ) Column( B2 to Left count cells in blank )
Range( C17 ) Column( B6 to Left count cells in blank )
Range( C18 ) Column( B9 to Left count cells in blank )
Range( C19 ) Column( B12 to Left count cells in blank )
Range( C20 ) Column( B15 to Left count cells in blank )

Your help I highly appreciate








Sub testing()
Dim home As Worksheet
Dim FNname AsString
Dim Wb As Workbook
Dim Tgt As Range

Set home = ActiveSheet

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
If .Show = -1 Then
Set Tgt = home.Cells(2, Columns.Count).End(xlToLeft).Offset(, 1)
FName = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
If FName <> FalseThen
Set Wb = Workbooks.Open(FName)
Wb.Worksheets("MAN_SUM").Range("H13:H16").Copy
Tgt.PasteSpecial xlPasteValues
Wb.Close False
EndIf
EndIf
End With
End Sub

Simon Lloyd
06-27-2008, 08:13 AM
KK1966 when posting code in future please wrap the VBA code tags around it by highlighting your code and clicking the green VBA button at the top of your post window.

KK1966
06-27-2008, 08:25 AM
Dear Simon

Sorry might it affect the forums!

is you means likes that? I try again it's


Sub testing()
Dim home As Worksheet
Dim FNname AsString
Dim Wb As Workbook
Dim Tgt As Range

Set home = ActiveSheet

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
If .Show = -1 Then
Set Tgt = home.Cells(2, Columns.Count).End(xlToLeft).Offset(, 1)
FName = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
If FName <> FalseThen
Set Wb = Workbooks.Open(FName)
Wb.Worksheets("MAN_SUM").Range("H13:H16").Copy
Tgt.PasteSpecial xlPasteValues
Wb.Close False
EndIf
EndIf
End With
End Sub

KK1966
06-27-2008, 08:27 AM
Sorry seem it the same! but i has highlighted and wrap with the vab button.

KK1966
06-27-2008, 08:35 PM
Brother's

Pleased, can help me how to modify the code to the copy methods

lucas
06-28-2008, 08:54 AM
Since you didn't offer us a sample of your data all I can do is offer this which shows you how to copy multiple ranges from a closed workbook. It is well commented so you shouldn't have too much trouble figuring it out.
Dim wb As Workbook
Application.ScreenUpdating = False ' turn off the screen updating

'Make path selections below
' Set wb = Workbooks.Open("f:\Temp\Social Club.xls", True, True)
Set wb = Workbooks.Open(ActiveWorkbook.Path & "\Social Club.xls")
' the sheet in this workbook to copy to
With ThisWorkbook.Worksheets("Final Results")
' read data from the source workbook
'the range to copy to in this workbook-name of sheet to copy FROM-range in closed workbook to copy
.Range("B7", "E36").Formula = wb.Worksheets("RESULTS").Range("B7", "E36").Formula
.Range("R7", "U36").Formula = wb.Worksheets("RESULTS").Range("R7", "U36").Formula

End With
wb.Close False ' close the source workbook without saving any changes
Set wb = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
End Sub

KK1966
06-29-2008, 01:53 AM
Thanks Lucas

Thanks your help and I Pleased to have you suggesting and advise, next I with
preparer the sample before,

your code is very gratefully.