+ Reply to Thread
Results 1 to 11 of 11

VBA Copy from another sheet & paste in cell where the formula is

Hybrid View

ch_abs VBA Copy from another sheet &... 01-16-2014, 06:01 AM
Swindon Dominic Re: VBA Copy from another... 01-16-2014, 10:09 AM
AB33 Re: VBA Copy from another... 01-16-2014, 10:16 AM
ch_abs Re: VBA Copy from another... 01-16-2014, 10:56 AM
ch_abs Re: VBA Copy from another... 01-16-2014, 10:57 AM
AB33 Re: VBA Copy from another... 01-16-2014, 11:00 AM
ch_abs Re: VBA Copy from another... 01-16-2014, 11:14 AM
AB33 Re: VBA Copy from another... 01-16-2014, 11:20 AM
AB33 Re: VBA Copy from another... 01-16-2014, 11:24 AM
ch_abs Re: VBA Copy from another... 01-16-2014, 11:30 AM
ch_abs Re: VBA Copy from another... 01-16-2014, 11:26 AM
  1. #1
    Registered User
    Join Date
    01-08-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2003=7
    Posts
    25

    VBA Copy from another sheet & paste in cell where the formula is

    Hi,

    I'm trying to copy a number from a worksheet 2, and paste it into the cell in worksheet 1 where I am inserting the formula.

    This is what I have so far:
    Function Copy_and_Paste(CellCopy As Range)
    
    Dim Sel_Val As Integer
    'user selects cell they want to copy
    CellCopy.Copy
    Worksheets("Main").Range(Copy_and_Paste).Paste
    
    
    End Function
    Currently, when I run it, it tries to paste the value into a random cell in worksheet 2, and when it does it just shows #VALUE!

    Thanks in advance

    UPDATE:

    I currently have the code below which returns a #VALUE! error now into the correct cell:
    Function Copy_and_Paste(CellCopy As Integer)
    
    Dim Sel_Val As Integer
    Worksheets("Mappings").Range(CellCopy).Value = Worksheets("Main").Range(ActiveCell).Value
    
    End Function
    Can I use ActiveCell as i have? :S
    Last edited by ch_abs; 01-16-2014 at 06:28 AM.

  2. #2
    Registered User
    Join Date
    01-24-2012
    Location
    Swindon, England
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: VBA Copy from another sheet & paste in cell where the formula is

    Hi

    I think your main problem is that CellCopy is an integer number whereas you want CellCopy to be a cell reference on worksheet 2. Are you trying to pick up the value for a numbered row in a given column?

    Regards

    Dominic

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Copy from another sheet & paste in cell where the formula is

    A function does not copy (Action), but return VALUES only, unless calling it. You need to change it to sub

  4. #4
    Registered User
    Join Date
    01-08-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2003=7
    Posts
    25

    Re: VBA Copy from another sheet & paste in cell where the formula is

    Hi,

    This is going to be part of something bigger but for now I want to copy a given value in Sheet2 ("Mappings") and paste it into the Active Cell of Sheet1 ("Main").

    Thanks for the help so far...
    Sub Copy2()
    
     Dim Sel_Val As Range
    
    Set Sel_Val = ActiveWorkbook.Worksheets("Mappings").Range("E4")
    Sel_Val.Select
    Sel_Val.Copy
    Worksheets("Main").ActiveCell.PasteSpecial xlValues
    
    End Sub

  5. #5
    Registered User
    Join Date
    01-08-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2003=7
    Posts
    25

    Re: VBA Copy from another sheet & paste in cell where the formula is

    Hi,

    This is going to be part of something bigger but for now I want to copy a given value in Sheet2 ("Mappings") and paste it into the Active Cell of Sheet1 ("Main").

    Thanks for the help so far...
    Sub Copy2()
    
     Dim Sel_Val As Range
    
    Set Sel_Val = ActiveWorkbook.Worksheets("Mappings").Range("E4")
    Sel_Val.Select
    Sel_Val.Copy
    Worksheets("Main").ActiveCell.PasteSpecial xlValues
    
    End Sub

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Copy from another sheet & paste in cell where the formula is

    Since you are copying in to active cell, you need to put the cursor on the active cell when you run the code.

    Sub Copy2()
    
    
    
    ActiveWorkbook.Worksheets("Mappings").Range("E4").Copy
    
    
    Worksheets("Main").ActiveCell.PasteSpecial xlValues
    
    End Sub

  7. #7
    Registered User
    Join Date
    01-08-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2003=7
    Posts
    25

    Re: VBA Copy from another sheet & paste in cell where the formula is

    Quote Originally Posted by AB33 View Post
    Since you are copying in to active cell, you need to put the cursor on the active cell when you run the code.

    Sub Copy2()
    
    
    
    ActiveWorkbook.Worksheets("Mappings").Range("E4").Copy
    
    
    Worksheets("Main").ActiveCell.PasteSpecial xlValues
    
    End Sub
    I have my cursor on the active cell and that is the one I have selected. When using your code I get the error "Object doesn't support this property or method".

    Thanks for your patience...new to this, this week!

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Copy from another sheet & paste in cell where the formula is

    Has the active cell got a name? Where is the active cell in sheet main? is in in A1, B1, etc?

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Copy from another sheet & paste in cell where the formula is

    Assuming you want to copy in to A1,

    Sub Copy2()
    
    ActiveWorkbook.Worksheets("Mappings").Range("E4").Copy
    
    
    Worksheets("Main").Range("A1").PasteSpecial xlValues
    
    Application.CutCopyMode = 0
    
    End Sub

  10. #10
    Registered User
    Join Date
    01-08-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2003=7
    Posts
    25

    Re: VBA Copy from another sheet & paste in cell where the formula is

    Quote Originally Posted by AB33 View Post
    Assuming you want to copy in to A1,

    Sub Copy2()
    
    ActiveWorkbook.Worksheets("Mappings").Range("E4").Copy
    
    
    Worksheets("Main").Range("A1").PasteSpecial xlValues
    
    Application.CutCopyMode = 0
    
    End Sub
    That worked great thanks when I put in an actual cell range!

  11. #11
    Registered User
    Join Date
    01-08-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2003=7
    Posts
    25

    Re: VBA Copy from another sheet & paste in cell where the formula is

    It's "P2" in Sheet Main.

    I really want to avoid setting the paste destination to a hard coded place because later on I want to use the copy&paste in a Function...this is assuming if I put "P2" in as the paste destination it would be an absolute cell reference?

+ 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. [SOLVED] Macro to copy a cell range and paste to a new sheet 'n' times where 'n' defined by formula
    By staminaboy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-26-2013, 11:39 AM
  2. How to copy data with formula and paste another sheet as paste spl -value only
    By sumesh56 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-14-2013, 09:03 PM
  3. Replies: 7
    Last Post: 12-03-2012, 03:10 AM
  4. Replies: 0
    Last Post: 05-24-2010, 05:17 PM
  5. Replies: 2
    Last Post: 10-15-2009, 10:12 AM

Tags for this Thread

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