Solved

Excel copy selected data

Posted on 2013-06-06
3
335 Views
Last Modified: 2013-06-06
I am trying to copy data from Sheet1 to Sheet2. Can anyone help me to do that.

I have tried these.
Worksheets("Sheet2").Range("A1:S1000").Value = Worksheets("Sheet1").Range("A1:S1000").Value

This copies A1 to S1000 data. I want to set these value dynamically to copy only the cells having data. My data starts from A1.


With this, I am able to copy the header. How can I expand this to copy all rows also.

With Worksheets("Sheet1").Range("A1")
  .Range(.Cells(1), .End(xlToRight)).Copy Destination:= Worksheets("Sheet2").Range("A1")
End With

Thanks in advace.
Sharath
0
Comment
Question by:Sharath
[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
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
Michael earned 250 total points
ID: 39227480
Hi Sharath,

you can use
With Worksheets("Sheet1")
  .Range("A1").Currentregion.Copy Destination:= Worksheets("Sheet2").Range("A1")
End With

Open in new window

However, this assumes there are no empty rows or empty columns in your dataset

You can also use:
to determine the last used row in a sheet:
.Cells(.Rows.Count, "A").End(xlUp).Row

Open in new window

and determine the last column:
.Cells(1, .Columns.Count).End(xlToLeft).Column

Open in new window


So, the determine the dataset try this:
With Worksheets("Sheet1")
  .Range(.Cells(1, 1), .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, .Cells(1, .Columns.Count).End(xlToLeft).Column)).Copy Destination:= Worksheets("Sheet2").Range("A1")
End With

Open in new window

0
 
LVL 41

Author Comment

by:Sharath
ID: 39227577
Thanks JazzyJoop. I tried your first suggestion and it is working. Will check the 2nd one also and close the question. Thanks again.
0
 
LVL 41

Author Comment

by:Sharath
ID: 39227619
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

628 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