+ Reply to Thread
Results 1 to 7 of 7

Copy Paste Special Values

Hybrid View

Lotus123 Copy Paste Special Values 01-19-2008, 11:02 AM
VBA Noob Maybe ... 01-19-2008, 11:08 AM
Lotus123 "Object doesn't support this... 01-19-2008, 11:11 AM
VBA Noob Instead of using Activesheet... 01-19-2008, 11:16 AM
Lotus123 Unfortunately, I cannot... 01-19-2008, 11:20 AM
  1. #1
    Forum Contributor Lotus123's Avatar
    Join Date
    11-07-2005
    Location
    Texas
    MS-Off Ver
    2007
    Posts
    153

    Copy Paste Special Values

    Can someone suggest an alternative to what I'm doing here. I get an error on the "copy/paste values" here...

    Masterbook.ActiveSheet.Range("A:D") = Tempbook.ActiveSheet.Range("A:D").Values
    Full Code

    Sub UpdateFS()
    Application.ScreenUpdating = False
    Dim Masterbook As Workbook
    Dim Tempbook As Workbook
    Dim Filename As String
    Dim Pathname As String
    Dim i As Integer
    Application.DisplayAlerts = False
    Set Masterbook = ActiveWorkbook
        For i = 1 To 2
            Filename = Range("M" & i).Text
            Pathname = "C:\Nathan\---COMPLETED REPORTS---\For Kristi\MONTHLY REPORTING\Wellington - Financial Statements\Consolidation\"
            Workbooks.Open Filename:=Pathname & Filename
            Set Tempbook = ActiveWorkbook
            If i = 1 Then
                Masterbook.ActiveSheet.Range("A:D") = Tempbook.ActiveSheet.Range("A:D").Values
                Tempbook.Close
            Else
                Masterbook.ActiveSheet.Range("F:I") = Tempbook.ActiveSheet.Range("A:D").Values
                Tempbook.Close
            End If
        Next i
        Application.DisplayAlerts = True
    End Sub
    Ecce Potestas Casei
    Nathan Head

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Maybe

    Masterbook.ActiveSheet.Range("A:D").Values= Tempbook.ActiveSheet.Range("A:D").Values
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Contributor Lotus123's Avatar
    Join Date
    11-07-2005
    Location
    Texas
    MS-Off Ver
    2007
    Posts
    153
    "Object doesn't support this property or method" on this line:

    Masterbook.ActiveSheet.Range("A:D").Values = Tempbook.ActiveSheet.Range("A:D").Values

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Instead of using Activesheet for both workbook re using the sheet names E.g

    Masterbook.Sheets("Sheet1").Range("A:D").Values = Tempbook.Sheets("Sheet1").Range("A:D").Values
    VBA Noob

  5. #5
    Forum Contributor Lotus123's Avatar
    Join Date
    11-07-2005
    Location
    Texas
    MS-Off Ver
    2007
    Posts
    153
    Unfortunately, I cannot specify a sheet name because I need the macro to operate on whatever sheet was selected when the macro started. The sheet name can be different each time I run the macro.

    I'm able to get the code to work as follows:
    Sub UpdateFS()
    Application.ScreenUpdating = False
    Dim Masterbook As Workbook
    Dim Mybook As String
    Dim Pathname As String
    Dim i As Integer
    Application.DisplayAlerts = False
    Set Masterbook = ActiveWorkbook
        For i = 1 To 2
            Mybook = Range("M" & i).Text
            Pathname = "C:\Nathan\---COMPLETED REPORTS---\For Kristi\MONTHLY REPORTING\Wellington - Financial Statements\Consolidation\"
            Workbooks.Open Filename:=Pathname & Mybook
            If i = 1 Then
                ActiveWorkbook.ActiveSheet.Range("A:D").Copy Destination:=Masterbook.ActiveSheet.Range("A:D")
                ActiveWorkbook.Close
            Else
                ActiveWorkbook.ActiveSheet.Range("A:D").Copy Destination:=Masterbook.ActiveSheet.Range("F:I")
                ActiveWorkbook.Close
        
            End If
        Next i
        Application.DisplayAlerts = True
    End Sub
    The above code was from another expert here, and it works great; however, I would prefer to only snag the values and not also the formats.

  6. #6
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845
    Hi,

    Modified code so that it paste values only.

    Sub UpdateFS()
    Application.ScreenUpdating = False
    Dim Masterbook As Workbook
    Dim Mybook As String
    Dim Pathname As String
    Dim i As Integer
    Application.DisplayAlerts = False
    Set Masterbook = ActiveWorkbook
        For i = 1 To 2
            Mybook = Range("M" & i).Text
            Pathname = "C:\Nathan\---COMPLETED REPORTS---\For Kristi\MONTHLY REPORTING\Wellington - Financial Statements\Consolidation\"
            Workbooks.Open Filename:=Pathname & Mybook
    
            If i = 1 Then
                ActiveWorkbook.ActiveSheet.Range("A:D").Copy
                Masterbook.ActiveSheet.Range("A:D").PasteSpecial (xlValues)
                ActiveWorkbook.Close
            Else
                ActiveWorkbook.ActiveSheet.Range("A:D").Copy
                Masterbook.ActiveSheet.Range("F:I").PasteSpecial (xlValues)
                ActiveWorkbook.Close
        
            End If
        Next i
        Range("A1").Select
        Application.DisplayAlerts = True
    End Sub
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1