Hi There
I appreciate your insight on this.
Problem starts at step 1. Then 2. …so on, excerpts below. Is a pivot table more efficient than transpose? What about the rest of the code? It keeps getting slower and never finishes in 1 hr. Task manager shows excel pegged at 13% cpu and 3.25GB memory (read somewhere that ~3gb is VBA’s limit) . I have office 365 64 bit, 100 GB SSD & 20 GB memory . win 7 64 bit.
Manual, no vba, pivot and charting works. Thank you.
'transpose sets of 3 on a 250K row dataset. got the following from this forum
ActiveCell.Formula = "=INDEX('Power Data Raw'!$B$2:$B$258898,ROWS(B$2:B2)*3-3+COLUMNS($B2:B2))"
' the following works on 20 cells
'Selection.AutoFill Destination:=Range("B2:D22")...doesn't bog down
'1. The following works and takes 2 mins
Selection.AutoFill Destination:=Range("B2:D86291"), Type:=xlFillDefault
' 2. The following takes 10 mins
'Change all the cells in a range to values to make it efficient.
With Range("B:D")
.Value = .Value
End With
Complete code below and dataset is at,
https://www.dropbox.com/sh/d57qcdkx6087u72/AACv4MqXDmpVrxN-Qci0Pjida?dl=0
Sub Macro2()
'
' Macro2 Macro
'
'delete raw columns
Range("A:A,C:H,J:AF,AH:AQ").Select
Range("AJ1").Activate
Selection.Delete Shift:=xlToLeft
' xlsb binary saves space
ActiveWorkbook.SaveAs FileFormat:=xlExcel12, CreateBackup:=False
' name sheet Power data Raw
Sheets(ActiveSheet.Name).Select
Sheets(ActiveSheet.Name).Name = "Power Data Raw"
'Fit
Cells.Select
Cells.EntireColumn.AutoFit
'name
Sheets.Add After:=ActiveSheet
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Total"
'transpose real power - temporary column
Range("B2").Select
'F8 = B2 delete me I is B, 8 is 2, $I$258904 is $B$258898, H8 is D2
'for 4 th generator make the following 4.
ActiveCell.Formula = "=INDEX('Power Data Raw'!$B$2:$B$258898,ROWS(B$2:B2)*3-3+COLUMNS($B2:B2))"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:D2"), Type:=xlFillDefault
Range("B2:D2").Select
'Selection.AutoFill Destination:=Range("B2:D22")...doesn't bog down
Selection.AutoFill Destination:=Range("B2:D86291"), Type:=xlFillDefault
'Change all the cells in a range to values
With Range("B:D")
.Value = .Value
End With
' B8 = A2
Range("A2").Select
' this is set for 4 generators
ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[4])"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A86291"), Type:=xlFillDefault
With Range("A:A")
.Value = .Value
End With
'delte temporary col
Columns("B:D").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
'transpose reactive power - temporary column
Range("B2").Select
'for 4 th generator make the following 4.
ActiveCell.Formula = "=INDEX('Power Data Raw'!$C$2:$C$258898,ROWS(B$2:B2)*3-3+COLUMNS($B2:B2))"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:D2"), Type:=xlFillDefault
Range("B2:D2").Select
'Selection.AutoFill Destination:=Range("B2:D22")...doesn't bog down
Selection.AutoFill Destination:=Range("B2:D86291"), Type:=xlFillDefault
'Change all the cells in a range to values
With Range("B:D")
.Value = .Value
End With
'this is different from above
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B2").Select
' this is set for 4 generators
ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[4])"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:B86291"), Type:=xlFillDefault
With Range("B:B")
.Value = .Value
End With
'delte temporary col
Columns("C:E").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
' time
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveCell.Formula = "=INDEX('Power Data Raw'!$A$2:$A$258898,ROWS(A$2:A2)*3-3+COLUMNS($A2:A2))"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A86291"), Type:=xlFillDefault
Range("A2").Select
Sheets("Power Data Raw").Select
ActiveWindow.SelectedSheets.Delete
ActiveWorkbook.Save
End Sub
I appreciate your insight on this.
Problem starts at step 1. Then 2. …so on, excerpts below. Is a pivot table more efficient than transpose? What about the rest of the code? It keeps getting slower and never finishes in 1 hr. Task manager shows excel pegged at 13% cpu and 3.25GB memory (read somewhere that ~3gb is VBA’s limit) . I have office 365 64 bit, 100 GB SSD & 20 GB memory . win 7 64 bit.
Manual, no vba, pivot and charting works. Thank you.
'transpose sets of 3 on a 250K row dataset. got the following from this forum
ActiveCell.Formula = "=INDEX('Power Data Raw'!$B$2:$B$258898,ROWS(B$2:B2)*3-3+COLUMNS($B2:B2))"
' the following works on 20 cells
'Selection.AutoFill Destination:=Range("B2:D22")...doesn't bog down
'1. The following works and takes 2 mins
Selection.AutoFill Destination:=Range("B2:D86291"), Type:=xlFillDefault
' 2. The following takes 10 mins
'Change all the cells in a range to values to make it efficient.
With Range("B:D")
.Value = .Value
End With
Complete code below and dataset is at,
https://www.dropbox.com/sh/d57qcdkx6087u72/AACv4MqXDmpVrxN-Qci0Pjida?dl=0
Sub Macro2()
'
' Macro2 Macro
'
'delete raw columns
Range("A:A,C:H,J:AF,AH:AQ").Select
Range("AJ1").Activate
Selection.Delete Shift:=xlToLeft
' xlsb binary saves space
ActiveWorkbook.SaveAs FileFormat:=xlExcel12, CreateBackup:=False
' name sheet Power data Raw
Sheets(ActiveSheet.Name).Select
Sheets(ActiveSheet.Name).Name = "Power Data Raw"
'Fit
Cells.Select
Cells.EntireColumn.AutoFit
'name
Sheets.Add After:=ActiveSheet
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Total"
'transpose real power - temporary column
Range("B2").Select
'F8 = B2 delete me I is B, 8 is 2, $I$258904 is $B$258898, H8 is D2
'for 4 th generator make the following 4.
ActiveCell.Formula = "=INDEX('Power Data Raw'!$B$2:$B$258898,ROWS(B$2:B2)*3-3+COLUMNS($B2:B2))"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:D2"), Type:=xlFillDefault
Range("B2:D2").Select
'Selection.AutoFill Destination:=Range("B2:D22")...doesn't bog down
Selection.AutoFill Destination:=Range("B2:D86291"), Type:=xlFillDefault
'Change all the cells in a range to values
With Range("B:D")
.Value = .Value
End With
' B8 = A2
Range("A2").Select
' this is set for 4 generators
ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[4])"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A86291"), Type:=xlFillDefault
With Range("A:A")
.Value = .Value
End With
'delte temporary col
Columns("B:D").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
'transpose reactive power - temporary column
Range("B2").Select
'for 4 th generator make the following 4.
ActiveCell.Formula = "=INDEX('Power Data Raw'!$C$2:$C$258898,ROWS(B$2:B2)*3-3+COLUMNS($B2:B2))"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:D2"), Type:=xlFillDefault
Range("B2:D2").Select
'Selection.AutoFill Destination:=Range("B2:D22")...doesn't bog down
Selection.AutoFill Destination:=Range("B2:D86291"), Type:=xlFillDefault
'Change all the cells in a range to values
With Range("B:D")
.Value = .Value
End With
'this is different from above
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B2").Select
' this is set for 4 generators
ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[4])"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:B86291"), Type:=xlFillDefault
With Range("B:B")
.Value = .Value
End With
'delte temporary col
Columns("C:E").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
' time
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveCell.Formula = "=INDEX('Power Data Raw'!$A$2:$A$258898,ROWS(A$2:A2)*3-3+COLUMNS($A2:A2))"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A86291"), Type:=xlFillDefault
Range("A2").Select
Sheets("Power Data Raw").Select
ActiveWindow.SelectedSheets.Delete
ActiveWorkbook.Save
End Sub