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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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