A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

copy array to new sheet



 
 
Thread Tools Display Modes
  #1  
Old May 27th, 2004, 11:52 AM
bypass
external usenet poster
 
Posts: n/a
Default copy array to new sheet

I am trying to automate the copying of values from a particular array on
one sheet of a work book to a blank sheet in the same work book.

The sheet that the values come from contains formulas and values, I am
only after the resulting values not the formulas

As this workbook is used as a template for altering differing sets of
data, the size of the array varies by the number of rows populated. The
number of columns remains the same.

Will this require a VB script?
Any suggestions.?


---
Message posted from http://www.ExcelForum.com/

  #2  
Old May 27th, 2004, 03:09 PM
Tushar Mehta
external usenet poster
 
Posts: n/a
Default copy array to new sheet

Since you haven't shared any specifics about worksheet names or the
columns that contains the info to be copied, I'll let you customize the
code below.

Suppose the data to be copied are in columns C:E, start in row 2, have
at least 2 rows, and are contiguous. Then, the code below should do
the job.

Sub testIt()
Dim DestSheet As Worksheet, SrcSheet As Worksheet
Set SrcSheet = ActiveSheet
Set DestSheet = SrcSheet.Parent.Worksheets.Add
With SrcSheet
.Activate
Range(.Range("c2"), .Range("c2").End(xlDown)).Resize(, 3).Copy
End With
DestSheet.Range("a1").PasteSpecial xlPasteValuesAndNumberFormats
End Sub


--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , bypass
says...
I am trying to automate the copying of values from a particular array on
one sheet of a work book to a blank sheet in the same work book.

The sheet that the values come from contains formulas and values, I am
only after the resulting values not the formulas

As this workbook is used as a template for altering differing sets of
data, the size of the array varies by the number of rows populated. The
number of columns remains the same.

Will this require a VB script?
Any suggestions.?


---
Message posted from http://www.ExcelForum.com/


  #3  
Old May 27th, 2004, 05:11 PM
bypass
external usenet poster
 
Posts: n/a
Default copy array to new sheet

Thanks Tushar

this looks like what I am after

However I am not familiar with VB and there is an error.

If I debug, this is where it is indicating a problem

DestSheet.Range("a1").PasteSpecial xPasteValuesAndNumberFormats


It did select the correct range and added in the new sheet but that is
as far as it got

any ideas?


---
Message posted from http://www.ExcelForum.com/

  #4  
Old May 27th, 2004, 05:54 PM
Tushar Mehta
external usenet poster
 
Posts: n/a
Default copy array to new sheet

You really need to provide more specific information.

What error message do you get? What version of XL are you using?

I tested the code with XL2003 before posting it.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , bypass
says...
Thanks Tushar

this looks like what I am after

However I am not familiar with VB and there is an error.

If I debug, this is where it is indicating a problem

DestSheet.Range("a1").PasteSpecial xPasteValuesAndNumberFormats


It did select the correct range and added in the new sheet but that is
as far as it got

any ideas?


---
Message posted from http://www.ExcelForum.com/


  #5  
Old May 27th, 2004, 06:04 PM
bypass
external usenet poster
 
Posts: n/a
Default copy array to new sheet

Sorry

ECXEL ver is 2000

error is run-time error '1004':
PasteSpecial method of Range class failed.

hope that helps


---
Message posted from http://www.ExcelForum.com/

  #6  
Old May 27th, 2004, 08:32 PM
Tushar Mehta
external usenet poster
 
Posts: n/a
Default copy array to new sheet

Ok, I don't know what is going on. If I try to run the code in XL2000,
I get a compile-time error 'Variable not defined' and the VBE points to
xlPasteValuesAndNumberFormats

Did you change anything in the code I posted?

Also, what do cells C2:C3 contain *before* you run the macro?

As long as the conditions laid out in my first post are met, the code
below works with XL2000. Hopefully, it also works with later versions.

Sub testIt()
Dim DestSheet As Worksheet, SrcSheet As Worksheet
Set SrcSheet = ActiveSheet
Set DestSheet = SrcSheet.Parent.Worksheets.Add
With SrcSheet
.Activate
Range(.Range("c2"), .Range("c2").End(xlDown)).Resize(, 3).Copy
End With
With DestSheet.Range("a1")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , bypass
says...
Sorry

ECXEL ver is 2000

error is run-time error '1004':
PasteSpecial method of Range class failed.

hope that helps


---
Message posted from http://www.ExcelForum.com/


  #7  
Old May 28th, 2004, 03:43 PM
bypass
external usenet poster
 
Posts: n/a
Default copy array to new sheet

Thanks for that Tushar

That did the trick.

Thanks for your patience


---
Message posted from http://www.ExcelForum.com/

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:24 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.