How to copy diffence range of sheets to another workboks with one time

sbv1986

Board Regular
Joined
Nov 2, 2017
Messages
77
Hi all:

I have code Brown to select excel files and copy Range("C11:J34") from sheets (2) to sheet("PL2") of Activeworkbook

Now I want to Brown to select excel files and copy Range("C11:J34") from sheets (2) to sheet("PL2") of Activeworkbook And copy Range("C9:N44") from sheets (4) to sheet("PL4") of Activeworkbook the same time.

How can I do that or could you change somethings of my code belove to do that:
This's my code
Code:
Sub SUM_WBs()    Sheets("PL2").Range("C11:J34").ClearContents
    
    Dim FileNameXls As Variant, i As Integer, wb As Workbook
    
    'ChDir = "C:\Temp\"      'Default directory
    
    FileNameXls = Application.GetOpenFilename(filefilter:="Excel Files, *.xl*", MultiSelect:=True)
    If Not IsArray(FileNameXls) Then Exit Sub    ' User cancelled
    
    Application.ScreenUpdating = False
    
    For i = LBound(FileNameXls) To UBound(FileNameXls)
    
        Set wb = Workbooks.Open(FileNameXls(i))
        wb.Sheets(2).Range("C11:J34").Copy  'Range of cells that needs to be sum
        ThisWorkbook.Sheets("PL2").Range("C11:J34").PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks:=True, Transpose:=False
        Application.CutCopyMode = False
        wb.Close SaveChanges:=False
      
    Next i
    Application.ScreenUpdating = True
    
End Sub

Thanks./.
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,203
Office Version
  1. 365
Platform
  1. Windows
How about
Code:
Sub SUM_WBs()
    
   Dim FileNameXls As Variant, i As Integer, wb As Workbook
   
   'ChDir = "C:\Temp\"      'Default directory
   Sheets("PL2").Range("C11:J34").ClearContents
   Sheets("PL4").Range("C9:N44").ClearContents
   
   FileNameXls = Application.GetOpenFilename(filefilter:="Excel Files, *.xl*", MultiSelect:=True)
   If Not IsArray(FileNameXls) Then Exit Sub    ' User cancelled
   
   Application.ScreenUpdating = False
   
   For i = LBound(FileNameXls) To UBound(FileNameXls)
      
      Set wb = Workbooks.Open(FileNameXls(i))
      wb.Sheets(2).Range("C11:J34").Copy  'Range of cells that needs to be sum
      ThisWorkbook.Sheets("PL2").Range("C11:J34").PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks:=True, Transpose:=False
      wb.Sheets(4).Range("C9:N44").Copy  'Range of cells that needs to be sum
      ThisWorkbook.Sheets("PL4").Range("C9:N44").PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks:=True, Transpose:=False
      Application.CutCopyMode = False
      wb.Close SaveChanges:=False
      
   Next i
   Application.ScreenUpdating = True
    
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,123,135
Messages
5,599,917
Members
414,348
Latest member
KloppyM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top