Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I optimise a set of VBA functions that parse String and Variant types
    primarykey
    data
    text
    <p>How can I optimise these functions? They work but I need it to be much faster.</p> <p>Actual working (slow):</p> <pre><code> Function IsInArray(value As String, arr As Variant) As Boolean Dim length As Integer Dim found As Boolean length = UBound(arr) found = False i = 0 While Not found And i &lt; length If arr(i) = value Then found = True End If i = i + 1 Wend If found Then IsInArray = True Else IsInArray = False End If End Function </code></pre> <p>This gets number of rows in specific list:</p> <pre><code>Function GetNumberOfRows(list As String) As Integer Dim numRows As Integer Dim row As Integer Dim column As Integer row = 2 column = 2 numRows = 0 While (Worksheets(list).Cells(row, column).value &lt;&gt; "") numRows = numRows + 1 row = row + 1 Wend GetNumberOfRows = numRows End Function </code></pre> <p>This replace values in a range</p> <pre><code>Sub ReplaceValue(oldValue As String, newValue As String, list As String) Dim numRows, numColumns As Integer Dim row, column As Integer numRows = GetNumberOfRows(list) numColumns = 9 row = 2 While row &lt;= numRows + 1 column = 3 While column &lt;= numColumns + 3 If Worksheets(list).Cells(row, column).value = oldValue Then Worksheets(list).Cells(row, column).value = newValue End If column = column + 1 Wend row = row + 1 Wend End Sub </code></pre> <hr> <p>P.S.</p> <p>This is fast but isn't to spec as if I'm searching for "aa", it will say TRUE if "aab" is in array. However it might be instructive to include it here as an example of 'fast'. </p> <pre><code>Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean IsInArray = (UBound(Filter(arr, stringToBeFound)) &gt; -1) End Function </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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