+ Reply to Thread
Results 1 to 7 of 7

Paste Value to selected cell of aother workbook FAILED

Hybrid View

nosense Paste Value to selected cell... 07-15-2015, 05:22 AM
LokeshKumar Re: Paste Value to selected... 07-15-2015, 05:25 AM
NeedForExcel Re: Paste Value to selected... 07-15-2015, 05:30 AM
nosense Re: Paste Value to selected... 07-15-2015, 06:13 AM
NeedForExcel Re: Paste Value to selected... 07-15-2015, 06:25 AM
nosense i did try to make it to work... 07-15-2015, 07:07 AM
NeedForExcel Re: Paste Value to selected... 07-15-2015, 08:04 AM
  1. #1
    Forum Contributor
    Join Date
    02-23-2015
    Location
    united kingdom
    MS-Off Ver
    14.0.7143.5000 (32-bit)
    Posts
    124

    Paste Value to selected cell of aother workbook FAILED

    Hi there here is my code but i get a error message saing that Method class for PasteSpecial has failed



    Sub InsertValues()



    'copy

    Range("D16").Select
    Selection.Copy

    'Opens Quality WB

    Dim fPath As String, fName As String
    Dim wb As Workbook

    fPath = "C:\Users\stan.kuncik\Desktop\Stan\"
    fName = fPath & "GKN Archimedes - GR Quality Sheet v1"

    Set wb = Workbooks.Open(fName)

    'Detects next empty cell and pastes rotor name

    'find
    '
    Application.DisplayAlerts = False
    Workbooks.Open (fName)
    Application.DisplayAlerts = True


    Sheets("GR").Select



    Range("c13").End(xlDown).Offset(1, 0).Select

    ActiveCell.PasteSpecial Paste:=xlPasteValues



    ActiveWorkbook.Save





    End Sub

  2. #2
    Forum Contributor LokeshKumar's Avatar
    Join Date
    03-31-2015
    Location
    India
    MS-Off Ver
    All, mostly 2010 now..
    Posts
    471

    Re: Paste Value to selected cell of aother workbook FAILED

    Could you please upload the workbook....so that I will get the same error.
    Lokesh Kumar
    Stay Hungry.. Stay Foolish..
    _________________________________________________________
    Please Click STAR to Add Reputation if my/someone's answer helped!

  3. #3
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Paste Value to selected cell of aother workbook FAILED

    Hi,

    Try this -

    Sub InsertValues()
    
        Range("D16").Copy
        
        Dim fPath As String, fName As String
        Dim wb As Workbook
        
        fPath = "C:\Users\stan.kuncik\Desktop\Stan\"
        fName = fPath & "GKN Archimedes - GR Quality Sheet v1"
        
        Set wb = Workbooks.Open(fName)    
        
        Sheets("GR").Select
        
        Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).Select
        
        ActiveCell.PasteSpecial Paste:=xlPasteValues
        
        ActiveWorkbook.Save
    
    End Sub
    By the way, the code can certainly be made a bit better.. However, I have just tried to get it working for now..
    Cheers!
    Deep Dave

  4. #4
    Forum Contributor
    Join Date
    02-23-2015
    Location
    united kingdom
    MS-Off Ver
    14.0.7143.5000 (32-bit)
    Posts
    124

    Re: Paste Value to selected cell of aother workbook FAILED

    Thank you for your replies.

    I have worked out that the problem occurs only when the workbook thats is to be open by macro is already open.

    Any ideas how to fix that so it work also with opened workbook.??
    Thanks

  5. #5
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Paste Value to selected cell of aother workbook FAILED

    Maybe something like this to check if the Workbook is open!

    Sub WBO()
        
        Dim wb As Workbook, Name As String, Counter As Integer
        
        For Each wb In Application.Workbooks
            Name = wb.Name
            
            If Name = "Array.xlsm" Then
                Counter = Counter + 1
            End If
            
        Next wb
        
        If Counter = 0 Then
            Workbooks.Open ("C:\Users\FinIQ\Desktop\Array.xlsm")
        End If
        
    End Sub

  6. #6
    Forum Contributor
    Join Date
    02-23-2015
    Location
    united kingdom
    MS-Off Ver
    14.0.7143.5000 (32-bit)
    Posts
    124
    Quote Originally Posted by NeedForExcel View Post
    Maybe something like this to check if the Workbook is open!

    Sub WBO()
        
        Dim wb As Workbook, Name As String, Counter As Integer
        
        For Each wb In Application.Workbooks
            Name = wb.Name
            
            If Name = "Array.xlsm" Then
                Counter = Counter + 1
            End If
            
        Next wb
        
        If Counter = 0 Then
            Workbooks.Open ("C:\Users\FinIQ\Desktop\Array.xlsm")
        End If
        
    End Sub

    i did try to make it to work in that it works for an open file as well but still an error
    i did:

    code:

    Sub InsertValues()
    'copy

    Range("D16").Select
    Selection.Copy
    'check if workbook is open
    Dim wb As Workbook, Name As String, Counter As Integer

    For Each wb In Application.Workbooks
    Name = wb.Name

    If Name = "GKN Archimedes - GR Quality Sheet v1" Then
    Counter = Counter + 1
    End If

    Next wb

    If Counter = 0 Then

    Workbooks.Open ("C:\Users\stan.kuncik\Desktop\Stan\GKN Archimedes - GR Quality Sheet v1")

    Sheets("GR").Select

    Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).Select

    ActiveCell.PasteSpecial Paste:=xlPasteValues


    End If



    If Counter <> 0 Then

    Workbooks("GKN Archimedes - GR Quality Sheet v1").Activate

    Sheets("GR").Select

    Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).Select

    ActiveCell.PasteSpecial Paste:=xlPasteValues


    End If
    ActiveWorkbook.Save



    End Sub

  7. #7
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Paste Value to selected cell of aother workbook FAILED

    See if this works

    Sub InsertValues()
        
        Dim Counter As Integer
        
        Dim fPath As String, fName As String
        Dim wb As Workbook
        
        fPath = "C:\Users\stan.kuncik\Desktop\Stan\"
        fName = "GKN Archimedes - GR Quality Sheet v1"
        
        Counter = WBO(fName)
        
        If Counter = 0 Then
            Workbooks.Open (fPath & fName)
        Else
            Workbooks(fName).Activate
        End If
            
        Sheets("GR").Select
        
        ThisWorkbook.Worksheets("Sheet1").Range("D16").Copy Cells(Rows.Count, "C").End(xlUp).Offset(1, 0)
        
        ActiveWorkbook.Save
    
    End Sub
    Function WBO(fName As String)
        
        Dim wb As Workbook, Name As String, Counter As Integer
        
        For Each wb In Application.Workbooks
            Name = wb.Name
            
            If Name = fName Then
                Counter = Counter + 1
            End If
            
        Next wb
        
        WBO = Counter
        
    End Function
    Change the sheet name in this line

    ThisWorkbook.Worksheets("Sheet1").Range("D16")

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. copy paste selected worksheets to new workbook as values
    By raj soni in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2014, 12:27 AM
  2. Replies: 5
    Last Post: 03-25-2014, 05:04 PM
  3. Replies: 1
    Last Post: 03-15-2014, 05:44 AM
  4. Replies: 2
    Last Post: 05-01-2013, 05:37 AM
  5. [SOLVED] Copy selected range of data and paste in new open workbook
    By coach.32 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2013, 03:41 AM
  6. Loop through data on a workbook, selected it and paste in current workbook
    By concatch in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-11-2012, 08:59 AM
  7. Replies: 3
    Last Post: 07-13-2009, 12:13 PM

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