Solved

Excel copy selected data

Posted on 2013-06-06
3
334 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

734 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