Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple of things you can do. First of all, declaring all variable saves memory which in turn saves time. That being said, the real time consuming factor in your code is the looping through each cell. The fastest way to obtain the same result is to read the data into an array and then write the array to the output sheet. In the following code, I have edited your <code>prepareOutput</code> sub in such a way, that it keeps your initial code structure, but instead of looping through and writing to each cell, it now reads the data into an array and then writes this array to the desired output area.</p> <pre><code>Sub prepareOutput() Application.ScreenUpdating = False Dim c As Range, d As Range, l As Range, ll As Range, r As Range Dim count As Integer Dim ArrDim As Integer, CurrVal As Integer Dim OutRng As Range Dim TempArr() As String 'Defines worksheets Dim WsEmph As Worksheet, WsOut As Worksheet Set WsEmph = ActiveWorkbook.Sheets("Ephemerides") Set WsOut = ActiveWorkbook.Sheets("Output") Set r = WsEmph.Range("a4:" &amp; Worksheets("Ephemerides").Range("a4").End(xlDown).Address) WsOut.Range("a3").Value = "Date" For Each d In r WsOut.Cells(d.Row, 1).Value = d.Value Next For Each c In WsEmph.Range("d2:o2") If Not IsEmpty(c) Then count = count + 5 'Redimension of temporary array ArrDim = WsEmph.Range(c.Offset(2, 0), c.End(xlDown)).Rows.count ReDim TempArr(1 To ArrDim, 1 To 2) CurrVal = 1 If count = 5 Then With WsOut .Cells(2, 2).Value = c.Value .Cells(3, 2).Value = "Longitude" .Cells(3, 3).Value = "Sign" .Cells(3, 4).Value = "Nakshatra" .Cells(3, 5).Value = "Navamsa" .Cells(3, 6).Value = "D60" End With For Each l In WsEmph.Range(c.Offset(2, 0), c.End(xlDown).Address) 'Fills array TempArr(CurrVal, 1) = l.Value TempArr(CurrVal, 2) = calcSign(l.Value) CurrVal = CurrVal + 1 Next 'Sets output range and writes data Set OutRng = WsOut.Range(WsOut.Cells(c.Offset(2, 0).Row, 2), WsOut.Cells(c.End(xlDown).Row, 3)) OutRng = TempArr count = 2 Else With WsOut .Cells(2, count).Value = c.Value .Cells(3, count).Value = "Longitude" .Cells(3, count + 1).Value = "Sign" .Cells(3, count + 2).Value = "Nakshatra" .Cells(3, count + 3).Value = "Navamsa" .Cells(3, count + 4).Value = "D60" End With For Each ll In WsEmph.Range(c.Offset(2, 0), c.End(xlDown).Address) 'Fills array TempArr(CurrVal, 1) = ll.Value TempArr(CurrVal, 2) = calcSign(ll.Value) CurrVal = CurrVal + 1 Next 'Sets output range and writes data Set OutRng = WsOut.Range(WsOut.Cells(c.Offset(2, 0).Row, count), WsOut.Cells(c.End(xlDown).Row, count + 1)) OutRng = TempArr End If End If Next Application.ScreenUpdating = True End Sub </code></pre> <p>On my system, running your code took <strong><em>25.16 seconds</em></strong>. With the above changes to the code it now takes just <strong><em>3.16 seconds</em></strong> to perform the same task. </p> <p>Note that I have also declared all variables and used worksheet-variables as refference to each worksheet. All though the latter doesn't improve speed, it only improves the readability of the code. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload