Copy from one workbook to another (just format and values)

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have this code below which is just pasting in the values (it works as expected). But under the section for Coverpage, when that is pasted in I want to Paste in both the format and values. But I dont want the formulas that are in the source so I cannot do "Paste"

(' Copy & Paste-Value: Coverpage Tab)

Any help is appreciated!

Code:
Sub Get_Data()

'Retriev_BOETab Macro
'
'
    ' Retrieve Current Workbook Name
    Dim Mtrl_Resource As Workbook
    Set Mtrl_Resource = ThisWorkbook
    
    Sheets("Tracker").Activate

    Application.ScreenUpdating = False
    
    ' Open Dialog Box to Select File to Copy From & Save it's Name in a Variable
    MsgBox "Retrieve the 'Material Estimates' tab from the Material Cost Estimates File - Select the MCE File."
    Dim filePicker As Office.FileDialog
    Set filePicker = Application.FileDialog(msoFileDialogFilePicker)
    With filePicker
        .Filters.Clear
        .Title = "Select an Excel File"
        .AllowMultiSelect = False
        .Filters.Add "Excel Files", "*.xlsx; *.xlsm; *.xls; *.xlsb", 1

        
        Dim selectedFile As String
        
        If .Show = True Then
            selectedFile = .SelectedItems(1)
        End If
    End With
    
    ' Open Selected File & Copy Data
    If selectedFile <> "" Then
        Dim MaterialEstBook As Workbook
        Dim sht As Worksheet, Flag As Boolean
        Set MaterialEstBook = Workbooks.Open(selectedFile, ReadOnly:=True)
        
        Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C6").Value = selectedFile
    
'***************************************************************************************************
        ' Copy & Paste-Value: Coverpage Tab
        
            'Unhide
            Workbooks(Mtrl_Resource.Name).Sheets("Coverpage").Visible = True
            
            'Check for tabs existence
            
            For Each sht In MaterialEstBook.Worksheets
            If LCase(sht.Name) = LCase("Coverpage") Then
            
            Workbooks(MaterialEstBook.Name).Worksheets("Coverpage").Range("A1:AC50000").Copy
            
            
            '################
            'Here is where I want it to paste it in as values but I also need the formatting from the source.  I cannot do "Paste" because the source has formulas which I don't want.
            'Thanks for the help
            '################

            Workbooks(Mtrl_Resource.Name).Worksheets("Coverpage").Range("A1").PasteSpecial _
                Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C7").Value = Now()
                
            Flag = True
            Exit For
            End If
            Next sht
            If Not Flag Then
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C7").Value = "Tab not found"
            End If
            Application.CutCopyMode = False
'***************************************************************************************************
        
'***************************************************************************************************
        ' Copy & Paste-Value: Task Input Tab
        
            'Unhide
            Workbooks(Mtrl_Resource.Name).Sheets("Tasks_Input").Visible = True
            
            'Check for tabs existence
            
            For Each sht In MaterialEstBook.Worksheets
            If LCase(sht.Name) = LCase("Tasks Input") Then
            
            Workbooks(MaterialEstBook.Name).Worksheets("Tasks Input").Range("A1:AC50000").Copy
            Workbooks(Mtrl_Resource.Name).Worksheets("Tasks_Input").Range("A1").PasteSpecial _
                Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C8").Value = Now()
                
            Flag = True
            Exit For
            End If
            Next sht
            If Not Flag Then
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C8").Value = "Tab not found"
            End If
            Application.CutCopyMode = False
'***************************************************************************************************

'***************************************************************************************************
        ' Copy & Paste-Value: Materials Input Tab
        
            'Unhide
            Workbooks(Mtrl_Resource.Name).Sheets("Materials_Input").Visible = True
            
            'Check for tabs existence
            
            For Each sht In MaterialEstBook.Worksheets
            If LCase(sht.Name) = LCase("Materials Input") Then
            
            Workbooks(MaterialEstBook.Name).Worksheets("Materials Input").Range("A1:AC50000").Copy
            Workbooks(Mtrl_Resource.Name).Worksheets("Materials_Input").Range("A1").PasteSpecial _
                Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C9").Value = Now()
                
            Flag = True
            Exit For
            End If
            Next sht
            If Not Flag Then
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C9").Value = "Tab not found"
            End If
            Application.CutCopyMode = False
'***************************************************************************************************

'***************************************************************************************************
        ' Copy & Paste-Value: Material_Distribution Tab
        
            'Unhide
            Workbooks(Mtrl_Resource.Name).Sheets("Material_Distribution").Visible = True
            
            'Check for tabs existence
            
            For Each sht In MaterialEstBook.Worksheets
            If LCase(sht.Name) = LCase("Material Distribution") Then
            
            Workbooks(MaterialEstBook.Name).Worksheets("Material Distribution").Range("A1:AC50000").Copy
            Workbooks(Mtrl_Resource.Name).Worksheets("Material_Distribution").Range("A1").PasteSpecial _
                Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C10").Value = Now()
                
            Flag = True
            Exit For
            End If
            Next sht
            If Not Flag Then
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C10").Value = "Tab not found"
            End If
            Application.CutCopyMode = False
'***************************************************************************************************

'***************************************************************************************************
        ' Copy & Paste-Value: Material_Assoc_Costs Tab
        
            'Unhide
            Workbooks(Mtrl_Resource.Name).Sheets("Material_Assoc_Costs").Visible = True
            
            'Check for tabs existence
            
            For Each sht In MaterialEstBook.Worksheets
            If LCase(sht.Name) = LCase("Material Assoc Costs") Then
            
            Workbooks(MaterialEstBook.Name).Worksheets("Material Assoc Costs").Range("A1:AC50000").Copy
            Workbooks(Mtrl_Resource.Name).Worksheets("Material_Assoc_Costs").Range("A1").PasteSpecial _
                Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C11").Value = Now()
                
            Flag = True
            Exit For
            End If
            Next sht
            If Not Flag Then
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C11").Value = "Tab not found"
            End If
            Application.CutCopyMode = False
'***************************************************************************************************

'***************************************************************************************************
        ' Copy & Paste-Value: Material_Ad_Hoc Tab
        
            'Unhide
            Workbooks(Mtrl_Resource.Name).Sheets("Material_Ad_Hoc").Visible = True
            
            'Check for tabs existence
            
            For Each sht In MaterialEstBook.Worksheets
            If LCase(sht.Name) = LCase("Material Ad Hoc") Then
            
            Workbooks(MaterialEstBook.Name).Worksheets("Material Ad Hoc").Range("A1:AC50000").Copy
            Workbooks(Mtrl_Resource.Name).Worksheets("Material_Ad_Hoc").Range("A1").PasteSpecial _
                Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C12").Value = Now()
                
            Flag = True
            Exit For
            End If
            Next sht
            If Not Flag Then
            Workbooks(Mtrl_Resource.Name).Worksheets("Tracker").Range("C12").Value = "Tab not found"
            End If
            Application.CutCopyMode = False
'***************************************************************************************************
                        
    
            ' Clear Clipboard
            Application.CutCopyMode = False
        
        
        
    
        ' Close Extra Workbook
        MaterialEstBook.Close SaveChanges:=False
        Set MaterialEstBook = Nothing
    End If
    
    Sheets("Tracker").Select

End Sub


Thank you!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
just repeat the pastevalues line but change xlPasteValues to xlPasteFormats
 
Upvote 0
Solution

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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