Mehedi Hassan

About author

Mehedi Hassan, having earned a BSc in Naval Architecture & Engineering from Bangladesh University of Engineering and Technology, functions as an Excel & VBA Content Developer at ExcelDemy. His deep interest in research and innovation aligns seamlessly with his fervor for Excel. In this role, Mehedi not only skillfully addresses challenging issues but also exhibits enthusiasm and expertise in gracefully navigating intricate situations, emphasizing his unwavering dedication to consistently delivering outstanding content. His interests are Advanced Excel, Data Analysis, Charts & Dashboards, Power Query, and Excel VBA. Apart from creating Excel tutorials, he is interested in Data Analysis with MS Excel, AutoCAD, Rhinoceros, ANSYS, Adobe Illustrator, Adobe Premiere Pro, and Report Writing.


Excel & VBA Content Developer at ExcelDemy in SOFTEKO.

Lives in

Dhaka, Bangladesh.


B.Sc. in Naval Architecture & Marine Engineering, BUET.


Microsoft Suite, AutoCAD, Rhinoceros, ANSYS, Adobe Illustrator, Adobe Premiere Pro


  • Technical Content Writing
  • Undergraduate Projects
    • Design of an Inland Cargo Vessel
    • Hydrodynamic Performance Analysis of a Hydrofoil Supported High Speed Vessel

Latest Posts From Mehedi Hassan

Excel Date Functions: A Complete Guide

In this article, we'll take you on a journey through the diverse range of powerful Excel date functions. From simple functions like DATE, TODAY, and NOW, to ...

Excel AutoFilter: A Complete Guide

In this article, you will learn about Excel AutoFilter. From enabling AutoFilter to applying different criteria, you will find them here. Filtering ...

Excel Form Control: A Complete Guide

In this article, you will learn how to insert and use Excel Form Control. This article will cover everything from turning on the Developer tab to inserting ...

How to Cut in Excel

In this article, you will learn how to cut in Excel with paste using different quick features. You will also learn to cut using formulas and multiple cells in ...

Suffix and Prefix in Excel: A Complete Guide

In this article, you will learn how to add suffix and prefix in Excel. You will learn to use functions like CONCATENATE, TEXT to add suffixes and prefixes. You ...

Subscript and Superscript in Excel: A Complete Guide

In this article, you will learn how to apply subscript and superscript in Excel. We’ve gathered numerous ways and you can apply these formatting to increase ...

How to Apply Excel Text Format

In this article, you will learn about Excel Text format. You will also learn about the TEXT function and the VBA FORMAT function which can be used to format ...

Excel VBA ColorIndex Chart

In this article, you will learn how to create an Excel VBA ColorIndex chart. You will also learn about the ColorIndex value which will let you create an ...

How to Use Excel VBA to Run Macro When Cell Value Changes

In this article, you will learn how to run VBA macro when cell value changes in Excel. We will show you 3 examples with simple explanations of each code to ...

How to Use Excel VBA to Add Comment to Cell (3 Examples)

In this article, you will learn how use Excel VBA to add comment to cell with VBA macro. We will demonstrate 3 examples to add comment to single cell, to ...

Excel VBA to Call Sub with Parameters (3 Suitable Examples)

If you are planning to learn Visual Basic for Applications (Excel VBA), one of the most basic tasks for you is to understand Subroutines with parameters and ...

Excel VBA Textbox to Format Date (4 Suitable Examples)

When working with UserForms in Excel VBA, it is often necessary to format the date values displayed in TextBox controls for a better user experience. Not only ...

How to Use Excel VBA DoEvents Function

Excel VBA DoEvents is a useful function that temporarily gives control back to the operating system. By allowing other processes to run while your macro is ...

Excel VBA to Show Message on Status Bar 

Customizing the Excel Status Bar message using VBA allows users to personalize their experience and gain valuable insights during the execution of macros or ...

Excel Reference Named Range in Another Sheet (3 Examples)

Excel's named range is a powerful tool that allows users to refer to a specific range of cells by a name rather than a cell address. This feature makes it ...

Browsing All Comments By: Mehedi Hassan
  1. Hello Bart,
    Thank you for reaching out. Your problem has a very simple solution. Instead of writing the code in a Sub Procedure, create an Event, Worksheet_SelectionChange in each of your Worksheet and simply paste your code.
    VBA Code for Event
    Do the same thing in every worksheet except the Index worksheet and modify the code as per your requirements. In this way, you don’t have to run the code every time.
    Here’s the modified code:

     Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim mVCount As Integer
        Dim mHCount As Integer
        Dim mVBreak As VPageBreak
        Dim mHBreak As HPageBreak
        Dim mNumPage As Integer
        mHCount = 1
        mVCount = 1
        If ActiveSheet.PageSetup.Order = xlDownThenOver Then
            mHCount = ActiveSheet.HPageBreaks.Count + 1
            mVCount = ActiveSheet.VPageBreaks.Count + 1
        End If
        mNumPage = 1
        For Each mVBreak In ActiveSheet.VPageBreaks
            If mVBreak.Location.Column > ActiveCell.Column Then Exit For
            mNumPage = mNumPage + mHCount
        For Each mHBreak In ActiveSheet.HPageBreaks
            If mHBreak.Location.Row > ActiveCell.Row Then Exit For
            mNumPage = mNumPage + mVCount
        ThisWorkbook.Worksheets("Worksheet 1").Range("I2").Value = "Page " & mNumPage & " of " & Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
        ThisWorkbook.Worksheets("Worksheet 3").Range("C5").Value = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
    End Sub

    Here is the result:
    Results of the code
    Hopefully, this will solve your problem.

    Hassan Shuvo || Exceldemy

  2. Hello Jaye,
    Hope you are doing well.
    #NAME error appears when you have a syntax problem in your formula. There shouldn’t be any #NAME error appearance when you add a new sheet to your workbook. We have checked out the VBA and the function and didn’t find any problem.

    We recommend you share your file or at least a Screenshot of the problem with us and we will get back to you about a solution.

    Hassan Shuvo || ExcelDemy

Advanced Excel Exercises with Solutions PDF