Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel copy selected data

Posted on 2013-06-06
3
Medium Priority
?
337 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
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
Michael earned 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

916 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