Copy data in a named range and paste values to first empty row in a range on a different sheet

hhnebula

New Member
Joined
May 15, 2006
Messages
15
I am new to VBA and am struggling to find the code for this simple action through the existing forum posts. If it is possible to assist me it would be much appreciated.

I have a named range on Sheet1 ("Sourcedata") referring to cells B10 to N10. I would like to copy the data in the range and paste as values into the first empty cell in a column range on Sheet2 (B10:B40). I have tried the following code but it does not work. Thanks in advance!

Code:
Sub Copy_Opportunity()

    Application.ScreenUpdating = False
    
    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet
    
    Set copySheet = Worksheets("Sheet1")
    Set pasteSheet = Worksheets("Sheet2")
        
    copySheet.Range("Sourcedata").Copy
    pasteSheet.Activate
              
    If pasteSheet.Range("B10:B40").Cells(1, 1).Value <> "" Then
        Set rngDst = pasteSheet.Range("B10:B40").Cells(1, 1).Offset(Range("B10:B40").Rows.Count - 1).End(xlUp).Offset(1)
        Set rngDst = pasteSheet.Range("B10:B40").Cells(1, 1)
    End If
       
    Selection.PasteSpecial Paste:=xlPasteValues
       
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi, maybe these small modifications..

Rich (BB code):
Sub Copy_Opportunity()


    Application.ScreenUpdating = False
    
    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet
    Dim rngdst As Range
    
    Set copySheet = Worksheets("Sheet1")
    Set pasteSheet = Worksheets("Sheet2")
        
    copySheet.Range("Sourcedata").Copy
    'pasteSheet.Activate 
              
    If pasteSheet.Range("B10:B40").Cells(1, 1).Value <> "" Then
        Set rngdst = pasteSheet.Range("B10:B40").Cells(1, 1).Offset(Range("B10:B40").Rows.Count - 1).End(xlUp).Offset(1)
    Else
        Set rngdst = pasteSheet.Range("B10:B40").Cells(1, 1)
    End If
       
    rngdst.PasteSpecial Paste:=xlPasteValues
       
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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