Share your favorite lines of code

When writing code sometimes you come across lines of code that allways gives you that warm feeling inside, every time you get the opportunity to use those lines of code.

Therefore I thought it would be fun to see if this could become interesting, stimulating, maybe even a learning topic. I’am also aware that things that sounds like a good idea in your head dont allways match the real world outcome, so this is kind of a experiment topic. :slight_smile: Rules: write some lines of your favorite code that gives you that extra good feeling every time you get the possibility to write those lines, it can be something technincal, fun, interesting, efficient, it can be almost anything (if direct relation to SAFE development then it is extra good". Write a short description if neccesary, also specify in which language the code is written. :slight_smile:

3 Likes

Visual basic, VBA for Excel.

This line allways makes me happy, when first started to code in excel and I wrote some do-until loops, it would many times go out of control and crash the program :joy: when I made mistakes until I found how to allways specify last row. :slight_smile:

”Find final row

finalrow = Sheets("data_get").Cells(Rows.Count, 1).End(xlUp).Row”

These lines of code I love because it opens up possibilities to write quite complex loops in loops for automatic calculations of big databases with different row lenghts. After many hours of searching I found a guy who specialized in arrays who gave me a solution for dynamic arrays. Before the solution it would not let me run code when lenght of array was not specified. :slight_smile:

”Define arrays, find last row

Dim ArrT(), ArrJa() As Variant

"Find last row

finalro = Sheets(“data_get”).Cells(Rows.Count, 9).End(xlUp).Row
finalrot = Sheets(“y_list”).Cells(Rows.Count, 1).End(xlUp).Row

’redim! Arrays to last row for two loops

ReDim ArrT(2 To finalro)
ReDim ArrJa(2 To finalrot)

’loop1
For a = 2 To finalro

ArrT(a) = Sheets("data_get").Cells(a, 9).Value

’loop2
For b = 2 To finalrot

   ArrJa(b) = Sheets("y_list").Cells(b, 1).Value
        If ArrJa(b) = ArrT(a) Then
            Sheets("y_list").Cells(b, 1).Interior.Color = rgbRed
                GoTo gfind
        End If
Next b

gfind:

Next a