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
Solved

Error: The selection is not valid

Posted on 2010-11-11
7
507 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

809 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