Tag: Excel VBA Tutorial

  • What Is VBA and Why It Matters for Excel Users – Complete Guide to Excel Automation and Productivity

    In the modern data-driven world, Microsoft Excel continues to be one of the most powerful and versatile tools used by professionals across industries. However, while most users rely on formulas, charts, and pivot tables, few realize the immense potential hidden beneath the surface—Visual Basic for Applications (VBA).

    VBA is Excel’s built-in programming language that allows users to automate tasks, create custom solutions, and enhance productivity like never before. From automating repetitive processes to building complete business applications, VBA in Excel can revolutionize the way you work.

    This comprehensive guide explores what VBA is, how it works, its benefits, practical applications, and why every serious Excel user should learn it.


    Understanding VBA – The Brain Behind Excel Automation

    VBA (Visual Basic for Applications) is a programming language developed by Microsoft that is integrated into all Office applications, including Excel, Word, PowerPoint, and Access.

    It acts as a bridge that lets users control Excel’s environment programmatically. In simple terms, VBA allows you to tell Excel exactly what to do, how to do it, and when to do it—without manual effort.

    AspectDescription
    Full FormVisual Basic for Applications
    TypeEvent-driven programming language
    Developed ByMicrosoft Corporation
    Used InExcel, Word, PowerPoint, Access, Outlook
    Primary PurposeAutomation and customization
    Base LanguageVisual Basic (VB)

    VBA provides access to Excel’s Object Model, enabling users to manipulate workbooks, worksheets, ranges, charts, and pivot tables through code.


    Why VBA Matters for Excel Users

    1. Automation of Repetitive Tasks

    VBA helps automate routine Excel operations such as:

    • Copying and pasting data
    • Formatting reports
    • Creating charts
    • Generating monthly MIS reports
    • Refreshing pivot tables

    For instance, instead of manually generating a report every Monday, a single VBA macro can do it automatically in seconds.

    2. Error Reduction

    Manual data handling often leads to mistakes. VBA scripts eliminate the risk of human error by executing consistent commands, ensuring accurate and repeatable results.

    3. Saves Time and Boosts Productivity

    Time-consuming processes like merging sheets, cleaning data, or updating dashboards can be automated using VBA. A 2-hour task can be reduced to just a few seconds with one click.

    4. Custom Functionality

    VBA allows you to build custom Excel functions (UDFs) not available by default. For example:

    Function GrossProfit(Sales, Cost)
        GrossProfit = Sales - Cost
    End Function
    

    This user-defined function calculates profit automatically whenever called in a cell.

    5. Integration Across Office Applications

    VBA can link Excel with Outlook, Word, or Access. For example, you can send bulk emails from Excel data using Outlook automation—saving hours of manual work.

    6. Empowers Non-Developers

    Unlike complex programming languages, VBA is relatively easy to learn. Even those without a technical background can use it to enhance their Excel performance significantly.


    How VBA Works Inside Excel

    To access VBA, open Excel → Developer Tab → Visual Basic or press ALT + F11.
    Here’s a breakdown of VBA’s core components:

    ComponentDescription
    VBA EditorThe interface where you write and edit VBA code.
    ModulesContainers that hold your VBA procedures or macros.
    Procedures (Subs/Functions)The actual VBA code that performs tasks.
    VariablesUsed to store data temporarily during code execution.
    ObjectsExcel elements like Workbooks, Worksheets, Ranges, etc.
    MethodsActions performed on objects (e.g., .Copy, .Save).
    PropertiesAttributes of objects (e.g., .Value, .Name).

    Example VBA Macro:

    Sub CreateReport()
        Sheets("Sales").Range("A1:F100").Copy
        Sheets("Report").Range("A1").PasteSpecial xlPasteValues
        MsgBox "Report Generated Successfully!"
    End Sub
    

    This script copies data from one sheet, pastes it into another, and displays a message upon completion.


    Real-Life Use Cases of VBA in Excel

    Use CaseExample
    Data CleaningRemoving duplicates, trimming spaces, and converting cases automatically.
    Report AutomationCreating monthly performance or sales reports with a single click.
    Dashboard UpdatingRefreshing pivot tables, charts, and KPIs instantly.
    Invoice GenerationAuto-creating invoices from a customer database.
    Email NotificationsSending emails directly from Excel when certain conditions are met.
    Database ManagementImporting/exporting data to and from Access or SQL Server.

    Difference Between Excel Formulas and VBA

    FeatureExcel FormulasVBA Macros
    FunctionalityBuilt-in calculationsCustom automation
    FlexibilityLimited to Excel functionsFully programmable
    Ease of UseEasy to use, no codingRequires basic coding knowledge
    SpeedSlower for large data setsFaster for automation
    User InteractionManual entryAutomated execution
    Cross-Application UseExcel onlyCan interact with Word, Outlook, Access

    Learning VBA – A Step-by-Step Approach

    1. Understand Excel’s Object Model
      Learn how Workbooks, Worksheets, and Ranges are structured and accessed.
    2. Record Macros
      Start with Excel’s built-in macro recorder to generate basic code automatically.
    3. Study VBA Syntax
      Understand variables, loops, conditions (If…Then…Else), and functions.
    4. Write Simple Scripts
      Try small automations like formatting data, inserting rows, or saving workbooks.
    5. Debug and Test
      Use the Immediate Window and Breakpoints to test your code step-by-step.
    6. Build Real Projects
      Automate dashboards, reports, or daily tasks for hands-on practice.

    Advantages of Learning VBA for Professionals

    ProfessionHow VBA Helps
    MIS ExecutiveAutomates daily data compilation and report generation.
    AccountantSpeeds up financial data processing and reconciliations.
    AnalystBuilds automated models for faster insights.
    HR ProfessionalGenerates attendance or payroll reports instantly.
    Data Entry OperatorMinimizes manual input and formatting errors.
    EntrepreneurSimplifies data tracking, billing, and performance reporting.

    Common Mistakes Beginners Make

    • Recording macros without cleaning the code
    • Forgetting to use Option Explicit (leads to variable errors)
    • Using hard-coded cell references instead of dynamic ranges
    • Ignoring error handling (On Error Resume Next)
    • Not backing up files before running macros

    Tips for Writing Efficient VBA Code

    • Use With…End With blocks for performance.
    • Avoid Select and Activate statements.
    • Use variables wisely and declare them properly.
    • Write reusable procedures for modular coding.
    • Always save a macro-enabled workbook (.xlsm) format.

    Conclusion

    VBA is much more than a coding tool—it’s a productivity powerhouse that transforms Excel from a static data platform into a dynamic automation engine. For anyone serious about career growth, mastering VBA means mastering Excel’s full potential.

    Whether you are an analyst, accountant, or business professional, learning VBA can save hundreds of hours annually, minimize errors, and elevate your data management skills to a professional level.


    Disclaimer

    The information in this article is intended for educational and informational purposes only. Readers are advised to test all VBA scripts in sample files before applying them to official or confidential data. The author assumes no responsibility for any data loss or issues arising from improper use of VBA.


  • How to Auto Refresh Your Pivot Table Data Automatically Using One Secret Excel Code

    One of the most common problems Excel users face while working with Pivot Tables is that the data doesn’t automatically update when new entries are added to the source table. You have to manually click Refresh every time to see the updated figures — and that’s both time-consuming and easy to forget.

    But here’s the secret: You can make Excel auto-refresh your Pivot Table data automatically every time you open your file or make changes to the dataset.
    Let’s understand how you can do this using a simple VBA (Visual Basic for Applications) code.


    Step 1: Ensure Your Data Is in an Excel Table

    Before you use any code, make sure your dataset is converted to a proper Excel Table:

    1. Select your data range.
    2. Press Ctrl + T (or go to Insert → Table).
    3. Ensure “My table has headers” is checked.
    4. Name your table something simple, like SalesData.

    This ensures that when new data is added, the Pivot Table’s source range expands automatically.


    Step 2: Insert the Secret Auto-Refresh Code

    Follow these steps carefully:

    1. Press Alt + F11 to open the VBA Editor window.
    2. In the left pane, double-click ThisWorkbook under your workbook name.
    3. Copy and paste the following VBA code:
    Private Sub Workbook_Open()
        Dim ws As Worksheet
        Dim pt As PivotTable
        
        'Loop through each worksheet
        For Each ws In ThisWorkbook.Worksheets
            'Loop through each PivotTable in the worksheet
            For Each pt In ws.PivotTables
                pt.RefreshTable
            Next pt
        Next ws
        
        MsgBox "All Pivot Tables have been refreshed automatically!", vbInformation
    End Sub
    

    Step 3: Save Your File as a Macro-Enabled Workbook

    Go to:

    • File → Save As
    • Select file type: Excel Macro-Enabled Workbook (*.xlsm)
    • Save and close your workbook.

    Now, every time you open this workbook, the code will automatically refresh all Pivot Tables and show a confirmation message.


    Step 4: Add Optional Auto-Refresh on Data Change

    If you regularly update your dataset while the file is open, you can make Excel auto-refresh the Pivot Table as soon as the source data changes. Here’s another version of the code:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim pt As PivotTable
        On Error Resume Next
        For Each pt In Me.PivotTables
            pt.RefreshTable
        Next pt
    End Sub
    

    How to use this:

    1. Right-click your data sheet tab.
    2. Select View Code.
    3. Paste the above code.
    4. Close the VBA editor and save your file again as .xlsm.

    Now, whenever you edit your source data, the Pivot Table automatically refreshes in the background — no clicks required.


    Step 5: Understanding How the Code Works

    Let’s break it down:

    • Workbook_Open() event triggers when you open your Excel file.
    • The loop scans through each worksheet and finds all Pivot Tables.
    • Each Pivot Table is refreshed using the RefreshTable command.
    • The final message box confirms completion.

    For the second code snippet:

    • Worksheet_Change() runs whenever any cell in that worksheet is modified.
    • It instantly updates all Pivot Tables linked to that data.

    This means your dashboards and reports are always showing real-time data without any manual effort.


    Step 6: Disable Macro Security Warnings (Optional)

    If Excel asks permission every time you open the file:

    1. Go to File → Options → Trust Center → Trust Center Settings.
    2. Click Macro Settings → Enable all macros (only for trusted files).
    3. Reopen your workbook.

    Step 7: Test It

    Now, add a new row of sales data in your table and save the file.
    Reopen it — you’ll notice the Pivot Tables instantly reflect the new figures.
    No need to click “Refresh” again!


    Bonus Tip: Refresh Specific Pivot Tables Only

    If you want to refresh only certain Pivot Tables instead of all, modify the code like this:

    Sub RefreshSpecificPivot()
        Sheets("Dashboard").PivotTables("PivotTable1").RefreshTable
        Sheets("Dashboard").PivotTables("PivotTable2").RefreshTable
    End Sub
    

    This is helpful for large dashboards with multiple Pivot Tables, where full refresh might slow things down.


    Advantages of Auto-Refreshing Pivot Tables

    BenefitDescription
    Saves TimeNo manual refresh needed every time data updates
    Avoids ErrorsPrevents forgetting to refresh before analysis
    Keeps Dashboards LiveAlways displays latest business metrics
    Ideal for ReportsPerfect for sales dashboards, MIS, and weekly performance sheets
    Enhances ProductivityFocus more on insights and less on clicking buttons

    When to Use This Method

    • When your Excel dashboard is used by multiple people.
    • When your workbook pulls data from an external source (e.g., CSV, Access, or SQL).
    • When you need always-updated reports for management presentations.
    • When you are creating automated sales or finance dashboards.

    Caution and Best Practices

    • Always keep a backup copy before using macros.
    • If your workbook is shared, inform users that macros are active.
    • Don’t use auto-refresh on extremely large datasets; it may slow down your file.
    • Periodically clean your Pivot Cache using Data → Refresh All → Options → Clear Cache to keep the file size small.

    Conclusion

    With this simple VBA automation, you’ve unlocked one of Excel’s most time-saving secrets — automatic Pivot Table refresh.
    You’ll never have to worry about outdated figures again. Just open your file, and Excel takes care of the rest.

    If you want to see this in real time, watch the complete video tutorial and share it with your friends and family so they can learn this professional shortcut too.


    Disclaimer

    This tutorial and VBA script are for educational purposes only. Always test your code in a copy of your workbook before applying it to live files. The author is not responsible for any data loss due to improper use of macros.


  • Create Multiple Pivot Tables in Excel Automatically Using VBA

    Pivot Tables are one of Excel’s most powerful tools for summarizing data and discovering insights. But if you’re working with large datasets and need multiple Pivot Tables, creating each one manually can be time-consuming and prone to error.

    In this tutorial, we’ll walk through a powerful Excel VBA macro that does all the hard work for you—automatically generating multiple Pivot Tables from your dataset in seconds.

    🧠 What You’ll Learn:

    • How to set up your data source dynamically using VBA
    • How to create multiple Pivot Tables using a single Pivot Cache
    • How to organize, format, and style each Pivot Table
    • How to combine rows, columns, and data fields in advanced Pivot Table design

    🛠 VBA Macro to Insert Multiple Pivot Tables

    Here’s the complete VBA script that automatically creates 8 categorized Pivot Tables plus one detailed summary Pivot Table:

    vbCopyEditSub Insert_Multiple_Pivot_Tables()
        ' Full VBA code here (omitted here for brevity)
    End Sub
    

    The macro performs the following key steps:


    🔄 1. Deletes and Recreates the “PivotTable” Sheet

    Ensures your output is always clean by removing any existing PivotTable sheet and creating a fresh one.


    📌 2. Dynamically Detects the Data Range

    Instead of hardcoding, it uses:

    vbaCopyEditLastRow = DSheet.Cells(Rows.Count, 1).End(xlUp).Row
    LastCol = DSheet.Cells(1, Columns.Count).End(xlToLeft).Column
    Set PRange = DSheet.Cells(1, 1).Resize(LastRow, LastCol)
    

    This makes your macro adaptable to datasets of varying lengths and widths.


    📦 3. Creates a Single Pivot Cache

    Instead of making a new cache for every Pivot Table (which increases file size), it smartly uses just one:

    vbaCopyEditSet PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=PRange)
    

    📈 4. Inserts 8 Thematic Pivot Tables:

    Each pivot summarizes a different aspect of the data:

    • Region-wise Total Sales
    • Product-wise Total Sales
    • Payment Mode-wise Sales
    • Delivery Status-wise Units
    • Customer Type-wise Sales
    • Order Priority-wise Units
    • Warranty-wise Units
    • Return Eligibility-wise Units

    Each is formatted with:

    vbaCopyEditpvt.ShowTableStyleRowStripes = True
    pvt.TableStyle2 = "PivotStyleDark2"
    

    📊 5. Adds a Detailed Multi-Dimensional Pivot Table

    At the end of the macro, a detailed sales pivot is generated with:

    • Row Fields: Region and Salesperson
    • Column Field: Product
    • Data Field: Total Sales (formatted as Revenue)

    The code includes:

    vbaCopyEditWith PTable.PivotFields("Total Sales")
        .Orientation = xlDataField
        .Function = xlSum
        .NumberFormat = "#,##0"
        .Name = "Revenue"
    End With
    

    And finally, it auto-adjusts column widths and zooms out to 80% for better readability.


    📂 Download the Excel Macro File


    (Make sure to enable macros after opening)


    💡 Why Use VBA for Pivot Tables?

    • ⚡ Speed: Create 8+ Pivot Tables instantly
    • 🔁 Automation: Run it anytime with new data
    • 📦 Efficiency: Uses a single Pivot Cache to reduce file size
    • 🎯 Customization: Easy to modify for different categories or fields

    ✍️ Final Thoughts

    With just a few lines of VBA, you can transform repetitive tasks into powerful automation tools. Pivot Tables offer deep insights—and now, you’ve just automated the whole process!

    Have questions or want to explore more Excel automation? Feel free to connect!


    Get the Free Training App

  • How to Convert Numbers to Words in Indian Rupees in Excel (With VBA)

    💰 How to Convert Numbers to Words in Indian Rupees in Excel

    Excel doesn’t have a built-in function to convert numbers to words (like “12345” → “Twelve Thousand Three Hundred Forty-Five”) — especially not in the Indian currency format like “Rupees Twelve Thousand Three Hundred Forty-Five Only”.

    But you can achieve this using a custom VBA function.


    ✅ Step-by-Step Guide: Convert Numbers to Words in Indian Rupees


    🧩 Step 1: Open VBA Editor

    1. Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
    2. Go to Insert > Module.

    ✍️ Step 2: Paste the VBA Code

    Paste the following code into the module window:

    Function ConvertToRupees(ByVal MyNumber)
        Dim Units As String
        Dim SubUnits As String
        Dim TempStr As String
        Dim Rupees As String
        Dim Paise As String
        Dim DecimalPlace As Integer
        Dim Count As Integer
        Dim Place(9) As String
        Dim NumDigit As Integer
        Dim Digit As Integer
        Dim MyNum As String
        Dim DecimalPart As String
        
        Place(2) = " Thousand "
        Place(3) = " Lakh "
        Place(4) = " Crore "
        
        ' Convert MyNumber to string and find position of decimal
        MyNumber = Trim(Str(MyNumber))
        DecimalPlace = InStr(MyNumber, ".")
        
        ' Split rupees and paise
        If DecimalPlace > 0 Then
            Paise = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
            MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
        End If
    
        Count = 1
        Do While MyNumber <> ""
            If Count = 1 Then
                TempStr = GetHundreds(Right(MyNumber, 3))
                If Len(MyNumber) > 3 Then
                    MyNumber = Left(MyNumber, Len(MyNumber) - 3)
                Else
                    MyNumber = ""
                End If
            Else
                TempStr = GetTens(Right(MyNumber, 2))
                If Len(MyNumber) > 2 Then
                    MyNumber = Left(MyNumber, Len(MyNumber) - 2)
                Else
                    MyNumber = ""
                End If
            End If
            If TempStr <> "" Then Rupees = TempStr & Place(Count) & Rupees
            Count = Count + 1
        Loop
    
        ConvertToRupees = "Rupees " & Rupees & IIf(Paise <> "", " and " & Paise & " Paise", "") & " Only"
    End Function
    
    Private Function GetHundreds(ByVal MyNumber)
        Dim Result As String
        If Val(MyNumber) = 0 Then Exit Function
        MyNumber = Right("000" & MyNumber, 3)
        If Mid(MyNumber, 1, 1) <> "0" Then
            Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
        End If
        If Mid(MyNumber, 2, 1) <> "0" Then
            Result = Result & GetTens(Mid(MyNumber, 2))
        Else
            Result = Result & GetDigit(Mid(MyNumber, 3))
        End If
        GetHundreds = Result
    End Function
    
    Private Function GetTens(TensText)
        Dim Result As String
        If Val(Left(TensText, 1)) = 1 Then
            Select Case Val(TensText)
                Case 10: Result = "Ten"
                Case 11: Result = "Eleven"
                Case 12: Result = "Twelve"
                Case 13: Result = "Thirteen"
                Case 14: Result = "Fourteen"
                Case 15: Result = "Fifteen"
                Case 16: Result = "Sixteen"
                Case 17: Result = "Seventeen"
                Case 18: Result = "Eighteen"
                Case 19: Result = "Nineteen"
                Case Else
            End Select
        Else
            Select Case Val(Left(TensText, 1))
                Case 2: Result = "Twenty "
                Case 3: Result = "Thirty "
                Case 4: Result = "Forty "
                Case 5: Result = "Fifty "
                Case 6: Result = "Sixty "
                Case 7: Result = "Seventy "
                Case 8: Result = "Eighty "
                Case 9: Result = "Ninety "
                Case Else
            End Select
            Result = Result & GetDigit(Right(TensText, 1))
        End If
        GetTens = Result
    End Function
    
    Private Function GetDigit(Digit)
        Select Case Val(Digit)
            Case 1: GetDigit = "One"
            Case 2: GetDigit = "Two"
            Case 3: GetDigit = "Three"
            Case 4: GetDigit = "Four"
            Case 5: GetDigit = "Five"
            Case 6: GetDigit = "Six"
            Case 7: GetDigit = "Seven"
            Case 8: GetDigit = "Eight"
            Case 9: GetDigit = "Nine"
            Case Else: GetDigit = ""
        End Select
    End Function
    

    🧪 Step 3: Use the Function in Excel

    After saving the VBA code:

    1. Go back to your Excel sheet.
    2. In any cell, enter:
    =ConvertToRupees(123456.78)
    or
    =ConvertToRupees(A2)
    
    *** Here A2 Cell contains numbers
    

    Output:
    Rupees One Lakh Twenty Three Thousand Four Hundred Fifty Six and Seventy Eight Paise Only


    📌 Notes:

    • Works with Indian Numbering System (Thousand, Lakh, Crore).
    • You must enable macros to use this function.
    • Use it in billing templates, invoices, payment receipts, etc.

    📣 Learn More Excel Automation Like This!

    🎓 Join My Excel Mastery Course
    Includes advanced functions, automation using VBA, and business templates with Indian formats.


    ✅ Here is your ready-to-use Excel template to convert numbers to words in Indian Rupees:

    📌 Important:

    This file includes:

    • Sample amounts in column A
    • A formula in column B using =ConvertToRupees(...)
    1. This is Macro enabled file. So you may get the warning. Just enabled the content if you are getting message in yellow and you are good to go.

    Breakdown of Excel VBA Function

    🔹 OVERVIEW OF THE MAIN FUNCTION: ConvertToRupees(ByVal MyNumber)

    This is the main function you call. It takes a numeric value (like 12345.50) and converts it into a full “Rupees … and … Paise” string.


    🔸 STEP 1: Variable Declarations

    vbaCopyEditDim Units As String, SubUnits As String, TempStr As String
    Dim Rupees As String, Paise As String
    Dim DecimalPlace As Integer, Count As Integer
    Dim Place(9) As String
    
    • Rupees: Final string for rupee part.
    • Paise: Final string for decimal part.
    • Place(): Array for Indian numbering system—Thousand, Lakh, Crore, etc.
    • Count: Keeps track of digit positions (units, thousands, lakhs…).
    • TempStr: Stores interim word values as they’re built.
    vbaCopyEditPlace(2) = " Thousand "
    Place(3) = " Lakh "
    Place(4) = " Crore "
    

    🔸 STEP 2: Handle Decimal and Integer Split

    vbaCopyEditMyNumber = Trim(Str(MyNumber))
    DecimalPlace = InStr(MyNumber, ".")
    
    • Converts the number to string, and finds the position of the decimal point (if it exists).
    • For example, 12345.50 becomes:
      • Rupee part: 12345
      • Paise part: 50
    vbaCopyEditIf DecimalPlace > 0 Then
        Paise = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    
    • Extracts the paise part using the GetTens function (explained later).
    • Ensures at least 2 digits by appending "00" and trimming.

    🔸 STEP 3: Main Loop to Build Words for Rupee Part

    vbaCopyEditCount = 1
    Do While MyNumber <> ""
    
    • Processes the rupee part in blocks of 3 or 2 digits, depending on the Indian number system.
    vbaCopyEditIf Count = 1 Then
        TempStr = GetHundreds(Right(MyNumber, 3))
    
    • First time, take the last 3 digits (i.e., units, tens, hundreds).
    vbaCopyEditElse
        TempStr = GetTens(Right(MyNumber, 2))
    
    • From second iteration onwards, take 2 digits at a time (i.e., thousands, lakhs, crores).
    vbaCopyEditIf TempStr <> "" Then Rupees = TempStr & Place(Count) & Rupees
    Count = Count + 1
    
    • Adds the word form to Rupees, prepending appropriate place name.

    🔸 STEP 4: Final Formatting

    vbaCopyEditConvertToRupees = "Rupees " & Rupees & IIf(Paise <> "", " and " & Paise & " Paise", "") & " Only"
    
    • Constructs the final string like:
      “Rupees Twelve Thousand Three Hundred Forty Five and Fifty Paise Only”

    🔹 SUPPORTING FUNCTIONS

    🔸 GetHundreds(MyNumber)

    • Converts a 3-digit number into words.
    • Example: "345" → "Three Hundred Forty Five"
    vbaCopyEditMyNumber = Right("000" & MyNumber, 3)
    
    • Pads numbers like "45" to "045" for consistent processing.
    vbCopyEditIf Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
    
    • If the hundred’s digit is not zero, convert it (e.g., 3 → “Three Hundred”).
    vbaCopyEditIf Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
    Else
        Result = Result & GetDigit(Mid(MyNumber, 3))
    End If
    
    • Handles the remaining 2 digits using GetTens.

    🔸 GetTens(TensText)

    • Converts 2-digit numbers to words.
    • Example: "45" → "Forty Five", "19" → "Nineteen"
    vbaCopyEditIf Val(Left(TensText, 1)) = 1 Then
        Select Case Val(TensText)
            Case 10: Result = "Ten"
            Case 11: Result = "Eleven"
            ...
    
    • Handles special case of numbers from 10 to 19.
    vbaCopyEditElse
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "Twenty "
            Case 3: Result = "Thirty "
            ...
    
    • Handles the tens place (20, 30, 40…).
    vbaCopyEditResult = Result & GetDigit(Right(TensText, 1))
    
    • Adds the unit place digit (e.g., 4 in 34).

    🔸 GetDigit(Digit)

    • Converts a single digit to its word form.
    • E.g., 1 → "One", 9 → "Nine"

    🔚 SUMMARY FLOW

    mathematicaCopyEditInput → "12345.50"
    ↓
    Split to "12345" (Rupees) and "50" (Paise)
    ↓
    Break into 3-2-2: 12 (Thousand), 345
    ↓
    → "Twelve Thousand Three Hundred Forty Five"
    → "Fifty Paise"
    ↓
    Output → "Rupees Twelve Thousand Three Hundred Forty Five and Fifty Paise Only"
    

    Best selling products