Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Error: The selection is not valid

Posted on 2010-11-11
7
Medium Priority
?
629 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the 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 will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

636 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