Unable to paste data

Dunk4Divin

New Member
Joined
Aug 21, 2019
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi

I am struggling to find out why this code wont work it's copying a variable range of data to another sheet but fails at the final hurdle of pasting. I've tried a variety of versions of the line but no good.

Any help would be appreciated!



Rich (BB code):
Sub ResetSummarySheet()

    Application.ScreenUpdating = False
   
    Sheets("Summary Filter").Select
    ActiveSheet.Unprotect Password:="0159"

        'Clears data below first row. The first row is then copied to the specified range
       
    Dim Rval2 As Variant
    Dim Cval2 As Variant
    Sheets("CalcData").Select
    Rval2 = ActiveSheet.Range("H2").Value
    Cval2 = ActiveSheet.Range("H3").Value
   
   
    Dim Rng2 As Variant
    Sheets("Summary Filter").Select
    Set Rng2 = Range(Cells(13, 1), Cells(Rval2, Cval2))
    Rng2.Select
    On Error GoTo EH:
    Selection.Clear

' Sets range to copy line of "Summary Filter" and paste from top to bottom of current "Condensed Data" range
        'set top row range using column count from CalcData sheet
EH:
    Dim Cval As Variant
    Sheets("CalcData").Select
   
        ' Summary Filter sheet Column count
   

    Cval = ActiveSheet.Range("H3").Value
   
   
    Dim Rval As Variant
    Sheets("CalcData").Select
   
 
        ' Condensed Data sheet row count
       
    Rval = ActiveSheet.Range("E2").Value
               
        ' Selects Summary Filtersheet and row to paste
    Dim Rng As Variant
    Sheets("Summary Filter").Select
    ActiveSheet.Unprotect Password:="0159"
    Call ClearFilters
    Set Rng = Range("BO12:EB12")
    Rng.Select
    Selection.Copy
   
        'Sets range to paste selected row into
       
       

    ActiveSheet.Unprotect Password:="0159"
    Set Rng = Range(Cells(12, 1), Cells(Rval + 10, Cval))
    Rng.Select
    Selection.Paste
    Application.Goto Reference:=Range("A12"), Scroll:=True
    Range("A12").Select
    Sheets("Summary Filter").Select
    Call GoToSummary


End Sub
 
Last edited by a moderator:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
it's copying a variable range of data to another sheet but fails at the final hurdle of pasting
Where does it change sheet in the part below?
VBA Code:
Set Rng = Range("BO12:EB12")
Rng.Select
Selection.Copy

'Sets range to paste selected row into



ActiveSheet.Unprotect Password:="0159"
Set Rng = Range(Cells(12, 1), Cells(Rval + 10, Cval))
Rng.Select
Selection.Paste
 
Upvote 0
Thanks for the response. It doesn't change sheet, but I added it in anyway but no good

Sub ResetSummarySheet()

Application.ScreenUpdating = False

Sheets("Summary Filter").Select
ActiveSheet.Unprotect Password:="0159"

'Clears data below first row. The first row is then copied to the specified range

Dim Rval2 As Variant
Dim Cval2 As Variant
Sheets("CalcData").Select
Rval2 = ActiveSheet.Range("H2").Value
Cval2 = ActiveSheet.Range("H3").Value


Dim Rng2 As Variant
Sheets("Summary Filter").Select
Set Rng2 = Range(Cells(13, 1), Cells(Rval2, Cval2))
Rng2.Select
On Error GoTo EH:
Selection.Clear

' Sets range to copy top line of "Summary Filter" and paste to bottom of current "Condensed Data" range
'set top row range using column count from CalcData sheet
EH:
Dim Cval As Variant
Sheets("CalcData").Select

' Summary Filter sheet Column count


Cval = ActiveSheet.Range("H3").Value


Dim Rval As Variant
Sheets("CalcData").Select


' Condensed Data sheet row count

Rval = ActiveSheet.Range("E2").Value

' Selects Summary Filtersheet and row to paste

Sheets("Summary Filter").Select
ActiveSheet.Unprotect Password:="0159"
Call ClearFilters
Range("BO12:EB12").Select
Selection.Copy

'Sets range to paste selected row into

Sheets("Summary Filter").Select
ActiveSheet.Unprotect Password:="0159"
Dim Rng3 As Variant
Set Rng3 = Range(Cells(12, 1), Cells(Rval + 10, Cval))
Rng3.Select
Selection.Paste
Application.Goto Reference:=Range("A12"), Scroll:=True
Sheets("Summary Filter").Select
Call GoToSummary


End Sub

Any other ideas please?
 
Upvote 0
I only asked because you stated in the question it did change sheet for the paste, try...

VBA Code:
    With Sheets("Summary Filter")
        .Unprotect Password:="0159"
        Call ClearFilters
        .Range("BO12:EB12").Copy .Cells(12, 1)
        Application.Goto .Range("A12"), True
    End With
 
Upvote 0
Solution
I had to change to the cell refs to include Rval & Cval and then it worked.

That's great thanks very much
 
Upvote 0
I had to change to the cell refs to include Rval & Cva
Why? you only need the top left cell of a range to make a paste

Edit:
Or are you copying the same data to multiple rows?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,079
Members
449,094
Latest member
mystic19

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