Hi, I’m a noob. No IT or coding knowledge. Just learn from macro recording and the net with a lot of trial and error. I hope this answer the questions why I cannot understand simple code while I can do the complex one, if any.
What my script do is:
Start
Prepare value from workbooks “WMaster” sheet “SMaster”
Text to Array from List (.txt)
Clear Sheet “RawData”
Loop For (From Arraylist)
Open new book
Insert raw data from .txt (html code), convert and repair data to excel
Copy data to workbooks “WMaster” Sheet “RawData”
Save result RawData
[RawData contain 3000 – 7000 row, and 36-40 columns of number, date, and some text depends on data source. And there is a possibility data increasing to 60 columns.]
Then Aplication.CalculationFull
[Calculate 14 sheet, 12 with UDF function, all sheet has precedents from RawData]
Create Report A1 to A4, take some value from report A paste in other Sheet for preparation creating report B
Save Report A1 to A4
Some Calculation
Clear Sheet “RawData”
End Loop
CreateReport B1-3
End
At the first line of code/script:
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
And reverse it at the end
My question or problem is in part Clear Sheet “RawData”
This is what I trying to do:
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Worksheets("RawData").EnableCalculation = False
Sheets("RawData").Cells.Clear ' Time : 00:00:08.757 - 00:00:09.506
' Sheets("RawData").Select
' Range("A1").Select
' Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
' Selection.Clear ' Time : 00:00:08.579 - 00:00:09.811
' Sheets("RawData").Select
' Range("A1").Select
' Cells.ClearContents ' Time : 00:00:08.605 - 00:00:09.758
' Sheets("RawData").Select
' For cr = 1 To 3500
' For cc = 1 To 40
' Cells(cr, cc) = "" 'Cells(Rows, Column)Sheet1
' Next cc
' Next cr ' Time : 00:02:31.831
' Worksheets("RawData").Range("A1:AN1560").Value = _
' Worksheets("Sheet1").Range("A1:" & "AN" & 1560).Value ' Time : 00:00:08.531 - 00:00:09.237
' col_cnt = Worksheets("RawData").UsedRange.Columns.Count
' Row_cnt = Worksheets("RawData").UsedRange.Rows.Count
Worksheets("RawData").Range(Worksheets("RawData").Cells(1, 1), _
Worksheets("RawData").Cells(Row_cnt, col_cnt)).Clear ' Time : 00:00:08.740 - 00:00:09.439
' Sheets("RawData").Select
' ActiveSheet.UsedRange.Delete ' Can;t Use Formula Connection also remove
I did try ForceFullCalculation set TRUE , the time to delete the sheet takes 00:00:00.025 - 00:00:00.055, but…. there is another piece of code that takes significantly longer
from 00:00:04.513 to 00:00:50.072, sometimes even more.
The part that take longer if ForceFullCalculation set TRUE is this:
Workbooks(Filename_MST).Activate
For x = LBound(ArrayDivCol) To UBound(ArrayDivCol)
ColDestClear = ArrayDivDestCol(x, 1) & 6 & ":" & ArrayDivDestCol(x, 1) & 206
Worksheets("Diver2").Range(ColDestClear).Clear
For y = LBound(ArrayDivSht) To UBound(ArrayDivSht)
ColLong = Worksheets(ArrayDivSht(y, 1)).Cells(Rows.Count, 1).End(xlUp).Row
ColSource = Worksheets(ArrayDivSht(y, 1)).Range(ArrayDivCol(x, 1) & ColLong)
Set Dicti = CreateObject("Scripting.Dictionary")
For z = 1 To UBound(ColSource, 1)
Dicti(ColSource(z, 1)) = 1
Next z
DivListCount = WorksheetFunction.CountA(Worksheets("Diver2").Range(ColDestClear))
DivListCount = DivListCount + 6
DivListCount_ = DivListCount
Sheets("Diver2").Range(ArrayDivDestCol(x, 1) & DivListCount).Resize(Dicti.Count) = Application.Transpose(Dicti.Keys)
Next y
AllRangSsrt = ArrayDivDestCol(x, 1) & "5:" & ArrayDivDestCol(x, 3) & 206
ASort1 = ArrayDivDestCol(x, 3) & 6 & ":" & ArrayDivDestCol(x, 3) & 206
ASort2 = ArrayDivDestCol(x, 2) & 6 & ":" & ArrayDivDestCol(x, 2) & 206
QueryPerformanceCounter StartTime11
Sheets("Diver2").Range(AllRangSsrt).Select
Application.Calculate
' Do Until Application.CalculationState = xlDone
' DoEvents
' MsgBox "Still Calculate Calc_All"
' Loop
If Not Application.CalculationState = xlDone Then
DoEvents
' MsgBox "Still Calculate Calc ALL"
End If
Sheets("Diver2").Range(AllRangSsrt).Select
ActiveWorkbook.Worksheets("Diver2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Diver2").Sort.SortFields.Add2 Key:=Range(ASort1 _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Diver2").Sort.SortFields.Add2 Key:=Range(ASort2 _
), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Diver2").Sort
.SetRange Range(AllRangSsrt)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Next x
QueryPerformanceCounter StartTime12
So is there a way to make the time consume to Clear Sheet “RawData” under 100 millisecond but the other part of the code run fast enough??
Thank you in advance
Bookmarks