LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default More efficient than copying and pasting

I wrote a program that calculates loads for an electric
company. Then it takes the loads that are greater than a
certain number and less than a certain number and puts
them into different sheets. Everything works fine, but
there is 22000+ rows of data and when I copying and paste
everything it is very slow, I was wondering if there was a
more efficient method of doing this. Here is the code
that I wrote:

Sub HighLoad()
' HighLoadFactor Macro
' Macro recorded 6/15/2004 by Dale D. Marques
' Declaring and Setting Variables
Worksheets("HighLoadFactor").Unprotect
Dim rng2 As Range
Set rng2 = Worksheets("Customer").Range("L7:L23000")
Worksheets("HighLoadFactor").Range
("A7:L23000").ClearContents
Worksheets("HighLoadFactor").Activate
Range("A7").Select
' For Loop High Load Factor
For a = 1 To rng2.Cells.Count
If rng2.Cells(a).Value = 0.9 Then
Worksheets("Customer").Range("A7:L7").Rows
(a).Copy
Worksheets("HighLoadFactor").Activate
Worksheets("HighLoadFactor").PasteSpecial
ActiveCell.Offset(rowoffset:=1).Select
End If
Next a
' Formatting Columns, Numbers, and Application
With Worksheets("HighLoadFactor").Columns("L")
.NumberFormat = "0.00"
.EntireColumn.AutoFit
End With
Worksheets("HighLoadFactor").Columns
("A:K").EntireColumn.AutoFit
Application.CutCopyMode = False
Range("A7:L23000").Sort Key1:=Range("L7"),
Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Worksheets("HighLoadFactor").Protect DrawingObjects =
True, contents = True, Scenarios = True
End Sub


Sub LowLoad()
' LowLoadfactor Macro
' Macro recorded 6/15/2004 by Dale D. Marques
' Declaring and Setting Variables
Worksheets("LowLoadFactor").Unprotect
Dim rng1 As Range
Set rng1 = Worksheets("Customer").Range("L7:L23000")
Worksheets("LowLoadFactor").Range
("A7:L23000").ClearContents
Worksheets("LowLoadFactor").Activate
Range("A7").Select
' For Loop Low Load Factor
For i = 1 To rng1.Cells.Count
If rng1.Cells(i).Value <= 0.1 And rng1.Cells(i)
< "" Then
Worksheets("Customer").Range("A7:L7").Rows
(i).Copy
Worksheets("LowLoadFactor").Activate
Worksheets("LowLoadFactor").PasteSpecial
ActiveCell.Offset(rowoffset:=1,
columnoffset:=0).Select
End If
Next i
' Formatting Columns, Numbers, and Application
With Worksheets("LowLoadFactor").Columns("L")
.NumberFormat = "0.00"
.EntireColumn.AutoFit
End With
Worksheets("LowLoadfactor").Columns
("A:K").EntireColumn.AutoFit
Application.CutCopyMode = False
Range("A7:L23000").Sort Key1:=Range("L7"),
Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Worksheets("LowLoadFactor").Protect DrawingObjects =
True, contents = True, Scenarios = True
End Sub

Sub LoadFactor()
' LoadFactorEquation Macro
' Macro recorded 6/16/2004 by Dale D. Marques
' Declaring and Setting Variables
Worksheets("Customer").Unprotect
Dim kWh As Range
Dim Demand As Range
Dim Days As Range
Dim Factor As Range
Set kWh = Worksheets("Customer").Range("G7:G23000")
Set Demand = Worksheets("Customer").Range("H7:H23000")
Set Days = Worksheets("Customer").Range("K7:K23000")
Set Factor = Worksheets("Customer").Range("L7:L23000")
Factor.ClearContents
' For Loop for Calculation
For i = 1 To kWh.Cells.Count
If kWh.Cells(i) <= 0 Then
Factor.Cells(i) = "0.00"
End If
If kWh.Cells(i) < "" And Demand.Cells(i) < 0 And
Days.Cells(i) < 0 Then
LF = Round(kWh.Cells(i) / (Demand.Cells(i) *
Days.Cells(i) * 24), 2)
Factor.Cells(i) = LF
End If
If Demand.Cells(i) = 0 And Demand.Cells(i) < ""
Then
Factor.Cells(i) = "0.00"
End If
If kWh.Cells(i) = "" And Demand.Cells(i) = "" And
Days.Cells(i) = "" Then
Factor.Cells(i) = ""
End If
If Days.Cells(i) = 0 And Days.Cells(i) < "" Then
Factor.Cells(i) = "0.00"
End If
Next i
' Formatting Columns and Application
Worksheets("Customer").Range("L7:L23000").NumberFo rmat
= "0.00"
Worksheets("Customer").Columns
("A:L").EntireColumn.AutoFit
Worksheets("Customer").Protect DrawingObject = True,
contents = True, Scenarios = True
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying and Pasting Kokomo Excel Discussion (Misc queries) 1 November 20th 07 02:14 PM
Copying and Pasting davew21 Excel Discussion (Misc queries) 1 March 31st 06 03:40 PM
Copying and pasting ??? NorcalTruck Excel Discussion (Misc queries) 3 December 27th 05 08:31 PM
Copying and Pasting Tia Excel Discussion (Misc queries) 4 June 6th 05 08:54 PM
Copying & Pasting Michael[_10_] Excel Programming 1 August 28th 03 11:00 AM


All times are GMT +1. The time now is 01:58 AM.

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

About Us

"It's about Microsoft Excel"