Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2005, 05:30 AM
Authorized User
 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help to define dynamic range

Hi,

I'm trying to write a code to copy some formulae from a spreadsheet named "ETSFALL" from Row 2 of Column T to AG to the rest of the rows under the same column. The problem i have is that the no. of rows is dynamic (In today's data, there's 26735 rows).

I have a code in blue below that is able to copy and paste the formula to the correct no. of rows but it is taking far too much time (> 10 mins). Does anyone know of a better way of doing this??

Please advise.
Thanks


Dim Range1 As String

Worksheets("ETSFALL").Select
ActiveCell.CurrentRegion.Select
Range1 = Selection.Rows.Count

Worksheets("ETSFALL").Cells(2, 1).Activate
Worksheets("ETSFALL").Cells(2, 1).Select
ActiveCell.CurrentRegion.Select
Count = Selection.Rows.Count

For i = 1 To Count
    Worksheets("ETSFALL").Range("T2:AG2").Copy
    Worksheets("ETSFALL").Cells(1 + i, 20).PasteSpecial
Next i



 
Old June 28th, 2005, 08:19 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Try to set Calculation to manual while copying the formulas

Application.Calculation = xlCalculationManual
'Do some copies here
Application.Calculation = xlCalculationAutomatic

-vemaju

 
Old June 28th, 2005, 11:01 PM
Authorized User
 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I managed to solve the problem. The code is shown below:

Dim Range1 As String

Worksheets("ETSFALL").Select
Worksheets("ETSFALL").Range("T2:AG2").Copy
ActiveCell.CurrentRegion.Select
Range1 = Selection.Rows.Count
Worksheets("ETSFALL").Cells(Range1, 20).Select
Worksheets("ETSFALL").Range(Selection, Selection.End(xlUp)).Select
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False

;p






Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Paste Dynamic Range jgrant Excel VBA 1 February 5th, 2008 10:13 PM
Combo box can not work with dynamic Range dahlia492 Excel VBA 1 November 20th, 2006 12:43 PM
Defining a Dynamic Range using a variable Alseikhan Excel VBA 0 March 27th, 2006 02:26 AM
Can u define difference ? gvcc_neel .NET Framework 2.0 4 October 10th, 2005 04:56 AM
find name and define range for Column qball Excel VBA 4 November 17th, 2004 03:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.