Solved

Selection not working

Posted on 2011-02-18
11
234 Views
Last Modified: 2012-05-11
Hi,

I have a piece of code to Count rows through Col A and Select Columsn A:M and Copy the selection but it dopes not seem to work, does it look okay?

Thanks
Seamus

With Sheets("Outstanding Items Report-1")
   r = .Range("A" & Rows.Count).End(xlUp).Row + 1
   .Range("A1:M" & r).Copy Workbooks("Asset Services Outstanding Stock Items.xls").Sheets("Outstanding Items Report-1").Cells(Rows.Count, "E").End(xlUp).Offset(1, -4)
End With
0
Comment
Question by:Seamus2626
  • 5
  • 4
  • 2
11 Comments
 
LVL 24

Expert Comment

by:broomee9
ID: 34927287
Try this:

With Sheets("Outstanding Items Report-1")
   r = .Range("A" & .Rows.Count).End(xlUp).Row + 1
   .Range("A1:M" & r).Copy Workbooks("Asset Services Outstanding Stock Items.xls").Sheets("Outstanding Items Report-1").Cells(Rows.Count, "E").End(xlUp).Offset(1, -4)
End With
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34927297
Seamus - does the code do anything, and if so what?
0
 

Author Comment

by:Seamus2626
ID: 34927375
Im trying to get ito to copy the selection A1:M and down (using E as the count)

Then i will paste it

Thanks
Seamus
0
 
LVL 24

Accepted Solution

by:
broomee9 earned 500 total points
ID: 34927459
What I pasted above works for me.  You are missing the dot (.) before the Rows.Count.
0
 

Author Closing Comment

by:Seamus2626
ID: 34927498
Sorry Broomee9, was just testing yours, all good!

Thanks
Seamus
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 24

Expert Comment

by:StephenJR
ID: 34927527
Ah missed that, though I don't understand why that should have caused a problem.
0
 
LVL 24

Expert Comment

by:broomee9
ID: 34927534
No worries, I've missed putting in the dots in my own code sometimes too.  It can happen to anyone. :-)
0
 
LVL 24

Expert Comment

by:broomee9
ID: 34927559
>>Ah missed that, though I don't understand why that should have caused a problem.

Without the dot, the Rows.Count refers to the ActiveSheet, so if you're not on the proper sheet when you run the code, then it will get the number of rows on the wrong sheet.  The dot (.) ties it to the specified sheet, so it doesn't matter what sheet you're on when you run the code.
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34927571
But I would have thought (clearly wrongly) that Rows.Count wouldn't change according to the sheet. Isn't it 65k.
0
 
LVL 24

Expert Comment

by:broomee9
ID: 34927639
Yes it is, but for the ActiveSheet, so it's A65536 on the ActiveSheet.

So if you have 50 rows of data in your desired sheet and 100 rows of data in your ActiveSheet r will return 100 without the dot and 50 with the dot.
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34927683
broomee9: thanks for sticking with me! I would have thought the first dot would cover that, but I think I see what you are saying.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
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 use longer labels with horizontal bar charts instead of the vertical column chart.

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now