Working with Numbers || Excel VBA Master Class || 3.4b

Note: This webpage is designed to accompany the Youtube video posted above. The video offers detailed explanation on all topics; while this webpage will serve as a repository for the code presented in the video. Source code will be presented in the order of the sections within the video.

Basics

Curious Case of the Decimal

Sub DoubleDecimal()
    Dim decDiv As Variant
    decDiv = CDec(22 / 7)
    
    Dim dblDiv As Double
    dblDiv = 22 / 7
End Sub

Checking if Number

Sub CleanData()
    Dim lrow As Long
    lrow = Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp).Row
    Dim i As Long
    For i = 2 To lrow
        If IsNumeric(Sheet1.Range("A" & i).Value) = False Or IsEmpty(Sheet1.Range("A" & i).Value) = True Then
            Sheet1.Range("A" & i).Value = 0
        End If
    Next i
End Sub


Sub CleanData()
    Dim lrow As Long
    lrow = Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp).Row
    Dim i As Long
    For i = 2 To lrow
        If Application.WorksheetFunction.IsNumber(Sheet1.Range("A" & i).Value) = False Then
            Sheet1.Range("A" & i).Value = 0
        End If
    Next i
End Sub

Arithmetic Operators

Sub UsingArithmeticOperators()

    Debug.Print (3 + 3) * 2
    
End Sub


Sub UsingArithmeticOperators()

    Debug.Print ((3 + 3) * 2) / 3
    
End Sub