?
Solved

Error: The selection is not valid

Posted on 2010-11-11
7
Medium Priority
?
651 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 800 total points
ID: 34113813
Line 5 should be Sheets("Request")
0
 
LVL 24

Expert Comment

by:Tracy
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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:
Tracy earned 1200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

749 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