Solved

Error: The selection is not valid

Posted on 2010-11-11
7
492 Views
Last Modified: 2012-05-10
Hi Experts,

The attached script shows error as “The selection is not valid” at this line:

.Range("A13:I" & n & ",M13:M" & n & ",Y13:AC" & n).Copy Sheets("Process").Range("A" & Rows.Count).End(xlUp)(2)

How to rectify this error? I have attached the workbook for Experts perusal. Hope Experts will help me.

Sub ArchiveData()

    Dim n As Long

With Sheets("Process")
    n = .Range("A" & Rows.Count).End(xlUp).Row
     .Range("A13:I" & n & ",M13:M" & n & ",Y13:AC" & n).Copy Sheets("Process").Range("A" & Rows.Count).End(xlUp)(2)
End With
    MsgBox "OK"
    
End Sub

Open in new window

CopyPaste.xls
0
Comment
Question by:Theva
7 Comments
 
LVL 24

Assisted Solution

by:StephenJR
StephenJR earned 200 total points
ID: 34113813
Line 5 should be Sheets("Request")
0
 
LVL 24

Expert Comment

by:broomee9
ID: 34113861
Try this instead, you are copy values to row 13, so you can't repaste them in that section the way you are trying.  Paste some where after row 13.

Sub ArchiveData()

    Dim n As Long

With Sheets("Process")
    n = .Range("A" & Rows.Count).End(xlUp).Row
     .Range("A13:I" & n & ",M13:M" & n & ",Y13:AC" & n).Copy .Range("A14")
End With
    MsgBox "OK"
    
End Sub

Open in new window

0
 
LVL 13

Expert Comment

by:gbanik
ID: 34113866
Your paste is happening on the same range as your source...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Theva
ID: 34114248
Hi StephenJR,

Need your help. How to set the data copied from row  13 to 37 only. When I add title at row 39, its copying that row as well which is shouldn't. Hope we can fix the range.

Hi broomee9,
Tested but its not copying data from request sheet to process sheet.
0
 
LVL 24

Accepted Solution

by:
broomee9 earned 300 total points
ID: 34114725
Your request is extremely unclear.  No where did you say you need to copy data from one sheet to another.  You asked to fix an error, which my original post fixes.  If you're looking to copy the data from Process to the end of the data in Request then try this.

Sub ArchiveData()

    Dim n As Long
    Dim p As Long
    
With Sheets("Process")
    n = .Range("A" & Rows.Count).End(xlUp).Row + 1
    p = Sheets("Request").Range("A" & Rows.Count).End(xlUp).Row + 1

    .Range("A3:I" & n & ",M3:M" & n & ",Y3:AC" & n).Copy Sheets("Request").Cells(p, 1)
End With
    MsgBox "OK"
    
End Sub

Open in new window

CopyPaste-2-.xls
0
 

Author Comment

by:Theva
ID: 34115107
Hi broomee9,

Apology for off track the question. Indeed yours and JR solution have resolved the problem, but I just realized that its also copying other cell data (after row 37) if column A  has a value.
0
 

Author Closing Comment

by:Theva
ID: 34115121
Hi,

Thanks for the help.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question