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

sbv1986

Board Regular
Joined
Nov 2, 2017
Messages
87
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./.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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
Back
Top