D
Dale Marques
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").NumberFormat
= "0.00"
Worksheets("Customer").Columns
("A:L").EntireColumn.AutoFit
Worksheets("Customer").Protect DrawingObject = True,
contents = True, Scenarios = True
End Sub
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").NumberFormat
= "0.00"
Worksheets("Customer").Columns
("A:L").EntireColumn.AutoFit
Worksheets("Customer").Protect DrawingObject = True,
contents = True, Scenarios = True
End Sub