# 12.6 Variables आणि data types

Source: https://ravindrabagale.com/mr/excel/ch12-macros-and-vba/12-6-variables-and-data-types.html
Language: mr (Marathi with English technical terms)

Variableमध्ये पुढे वापरायची value ठेवतो. Syntax Dim name As Type.

 | Type | कशासाठी? | Example

 | Long | Row numbers, integer counts. | Dim orders As Long

 | Double | Decimal calculations. | Dim sales As Double

 | Currency | चार fixed decimal placesचं numeric type. | Dim fee As Currency

 | String | Text. | Dim city As String

 | Date | Date/time. | Dim orderDate As Date

 | Boolean | True/False. | Dim isLate As Boolean

 | Variant | वेगवेगळे value types. | Dim v As Variant

 | Worksheet / Range | Excel objects. | Dim ws As Worksheet

Object assign करायला Set ws = ThisWorkbook.Worksheets("Orders").

Sub VariablesDemo()
    Dim city As String
    Dim orders As Long
    Dim sales As Double
    Dim aov As Double
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Worksheets("Orders")
    city = "Pune"
    orders = Application.WorksheetFunction.CountIfs(ws.Range("C:C"), city)
    sales = Application.WorksheetFunction.SumIfs(ws.Range("G:G"), ws.Range("C:C"), city)

    If orders > 0 Then aov = sales / orders
    MsgBox city & ": " & orders & " orders, AOV Rs " & Format(aov, "0.00")
End Sub

Mini dataset: Puneचे 4 order rows, sales ₹544, average ₹136. Source count row-based आहे; repeated Order IDs असतील तर distinct order AOV नाही. Count zero असल्यास source codeचा initialized aov 0 राहतो; real reportमध्ये “No orders” वेगळं दाखवणं अधिक स्पष्ट.

Practice

Nashikचा row count, sales आणि average Delivery Mins variablesमध्ये घेऊन MsgBox करा. Count zero आणि nonnumeric timesचं handling ठरवा.

रवींद्र बागले यांची tip

VBA Integerची maximum value 32,767; मोठ्या sheetच्या row countersसाठी Long वापरा. Dim a, b As Longमध्ये फक्त b Long होतो—प्रत्येक variableचा type स्पष्ट लिहा.
