Copy Paste Error

londa_vba

Board Regular
Joined
May 11, 2023
Messages
61
Office Version
  1. 365
Platform
  1. Windows
Could someone please explain what I have incorrect in the following code?
I get an error at the last line in the code = ActiveCell.PasteSpecial xlPasteValues
I am trying to have the range copy and paste into whatever cell is selected before the macro is run.

VBA Code:
Sub PopulateCEPrepYFP()
Dim arrRanges() As String
Dim arrWorksheets() As String
Dim Ws As Worksheet
Dim i As Integer
Dim ii As Integer
Dim intRow As String
Dim rng As Range

    ActiveWorkbook.Save
    
    Worksheets("CE Prep").Activate
    
    With Worksheets("CE Prep")
        .Range("Ag3:Ag" & .Cells(.Rows.Count, "AA").End(xlUp).Row).Value = ""
    End With

    arrRanges = Split("B8:B33,B39:B64,B70:B95,B101:B126", ",")
        
    arrWorksheets = Split("YFP Amp Setup", ",")
    
    intRow = 3
    
    For i = LBound(arrWorksheets) To UBound(arrWorksheets)
        
        For ii = LBound(arrRanges) To UBound(arrRanges)
            
            For Each rng In Worksheets(arrWorksheets(i)).Range(arrRanges(ii))
                If Len(Trim(rng.Value)) > 0 Then
                    Worksheets("CE Prep").Cells(intRow, 33).Value = rng.Value
                    intRow = intRow + 1
                End If
            Next rng
            
        Next ii
        
    Next i
    
    Worksheets("CE Prep").Range("Ag3").Select
    
                

Worksheets("CE Prep").Range("AH2:Ak99").Copy
ActiveCell.PasteSpecial xlPasteValues
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try:

ActiveCell.PasteSpecial Paste:=xlPasteValues
Hi I figured it out. The problem was two lines above where I selected a new cell in the code than the one I clicked on before I ran it. It is working as expected now. Thank you for your time
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,953
Members
449,095
Latest member
nmaske

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