Copying Values between workbooks

termeric

Active Member
Joined
Jun 21, 2005
Messages
280
Hello, I am using the code below to loop through a series of workbooks and copy 2 of the tabs over. I'm running into a problem where some of the formulas included on the sheet are If statements, and they end up all false because i am not copying over the tab that they are analyzing. is there a way to copy over the values in the cells instead of the formulas?


Code:
    xSheetName = "Rate Sch ED6"
    xRgStr = "A1:G50"
    zSheetName = "Rate Sheet"
    zRgStr = "A1:G50"
    
    Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    With xFileDlg
        If .Show = -1 Then
            xSelItem = .SelectedItems.Item(1)
            Set xWorkBook = ThisWorkbook
            Set xSheet = xWorkBook.Sheets("New Sheet")
            If xSheet Is Nothing Then
                xWorkBook.Sheets.Add(after:=xWorkBook.Worksheets(xWorkBook.Worksheets.Count)).Name = "New Sheet"
                Set xSheet = xWorkBook.Sheets("New Sheet")
            End If
            
            Set zSheet = xWorkBook.Sheets("New Sheet 2")
            If zSheet Is Nothing Then
                xWorkBook.Sheets.Add(after:=xWorkBook.Worksheets(xWorkBook.Worksheets.Count)).Name = "New Sheet 2"
                Set zSheet = xWorkBook.Sheets("New Sheet 2")
            End If
            xFileName = Dir(xSelItem & "\*.xlsm", vbNormal)
            If xFileName = "" Then Exit Sub
            Do Until xFileName = ""
                Sheets("New Sheet").Cells.Delete Shift:=xlUp
                Sheets("New Sheet 2").Cells.Delete Shift:=xlUp
            
                Set xBook = Workbooks.Open(xSelItem & "\" & xFileName)
                Set xRg = xBook.Worksheets(xSheetName).Range(xRgStr)
                xRg.Copy xSheet.Range("A65536").End(xlUp).Offset(0, 0)
                
               
                Set xBook = Workbooks.Open(xSelItem & "\" & xFileName)
                Set zRg = xBook.Worksheets(zSheetName).Range(zRgStr)
                zRg.Copy zSheet.Range("A65536").End(xlUp).Offset(0, 0)
                
                xFileName = Dir()
                xBook.Close
                
                'massage the data
                GroupInfo
                RateSch
                Sheets("Group Info Summary").Range("A" & x + 13).Value = x
                x = x + 1

                
                
            Loop
        End If
    End With
[\code]
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Instead of doing a straight copy to the destination, do a copy (into the clipboard), then do a PasteSpecial of values into the destination.

Like:
xRg.Copy xSheet.Range("A65536").End(xlUp).Offset(0, 0).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Another option, bypassing the clipboard.
VBA Code:
xSheet.Range("A65536").End(xlUp).Offset(0, 0).Resize(xRg.Rows.Count, xRg.Columns.Count).Value = xRg.Value
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

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