SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
Useful Macros and functions for Excel




        This knowledge asset has information pertaining to Excel Macros and useful Functions.




         This document will let you know about some useful macros and functions, which are frequently
used by the users.



Topics Covered:


1.   Macro for Deleting Blank columns from a worksheet................................................................................ 1
2.   Macro uploading rows more than 65536. ................................................................................................... 2
3.   Macro for removing un-necessary columns from a worksheet................................................................... 3
4.   Formula for finding matching values present in column A and Column B................................................ 5
5.   Formula for showing distinct values in a column. ...................................................................................... 6




                                                                                                        Developer: Nihar R Paital
1. Macro for Deleting Blank columns from a worksheet.
We need to delete the column B, E as they are blank.


The below is the Procedure.

   1 Click "Tools," select "Macro" and choose "Macros."
   2 Type a name for your macro in the "Name" field, such as "DeleteBlankColumns" and click "Create."
   The Visual Basic Editor will open automatically.
   3 Double-click "(Name) Module" in the "Properties" window and type a name say "DeleteBlankCol"
   4 Click the "+" icon next to "Microsoft Excel Objects."
   5 Double-click "DeleteBlankCol" to open the "Code" window.
   6 Copy and paste the following into the "Code".

           Dim Col As Long, ColCnt As Long, Rng As Range
             Application.ScreenUpdating = False
             Application.Calculation = xlCalculationManual
           On Error GoTo Exits:
             If Selection.Columns.Count > 1 Then
                Set Rng = Selection
             Else
                Set Rng = Range(Columns(1), Columns(ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column()))
             End If
             ColCnt = 0
             For Col = Rng.Columns.Count To 1 Step -1
                If Application.WorksheetFunction.CountA(Rng.Columns(Col).EntireColumn) = 0 Then
                   Rng.Columns(Col).EntireColumn.Delete
                   ColCnt = ColCnt + 1
                End If
             Next Col
           Exits:
             Application.ScreenUpdating = True
             Application.Calculation = xlCalculationAutomatic

   7 Save the Macro.
   8 Click "Tools," select "Macro" and choose "Macros."
   9 Select the "DeleteBlankColumns" macro from the "Macros" dialog box and click "Run."
   This will delete all the blank columns. Like B and E.




                                                                                   Developer: Nihar R Paital
2. Macro uploading rows more than 65536.
 1 Create a text file say myhugedocument.txt having number of lines more than 65536.
 2 Click "Tools," select "Macro" and choose "Macros."
 3 Type a name for your macro in the "Name" field, such as "ImportFile" and click "Create." The Visual
 Basic Editor will open automatically.
 4 Double-click "(Name) Module" in the "Properties" window and type a name say "FileImport"
 5 Click the "+" icon next to "Microsoft Excel Objects."
 6 Double-click "FileImport" to open the "Code" window.
 7 Copy and paste the following into the "Code".

        'Dimension Variables
        Dim ResultStr As String
        Dim FileName As String
        Dim FileNum As Integer
        Dim Counter As Double
        'Ask User for File's Name
        FileName = InputBox("Please enter the Text File's name, e.g. test.txt")
        'Check for no entry
        If FileName = "" Then End
        'Get Next Available File Handle Number
        FileNum = FreeFile()
        'Open Text File For Input
        Open FileName For Input As #FileNum
        'Turn Screen Updating Off
        Application.ScreenUpdating = False
        'Create A New WorkBook With One Worksheet In It
        Workbooks.Add template:=xlWorksheet
        'Set The Counter to 1
        Counter = 1
        'Loop Until the End Of File Is Reached
        Do While Seek(FileNum) <= LOF(FileNum)
        'Display Importing Row Number On Status Bar
        Application.StatusBar = "Importing Row " & _
        Counter & " of text file " & FileName
        'Store One Line Of Text From File To Variable
        Line Input #FileNum, ResultStr
        'Store Variable Data Into Active Cell
        If Left(ResultStr, 1) = "=" Then
        ActiveCell.Value = "'" & ResultStr
        Else
        ActiveCell.Value = ResultStr
        End If
        'For Excel versions before Excel 97, change 65536 to 16384
        If ActiveCell.Row = 65536 Then
        'If On The Last Row Then Add A New Sheet
        ActiveWorkbook.Sheets.Add
        Else
        'If Not The Last Row Then Go One Cell Down
        ActiveCell.Offset(1, 0).Select
        End If
        'Increment the Counter By 1
        Counter = Counter + 1
        'Start Again At Top Of 'Do While' Statement
        Loop
        'Close The Open Text File

                                                                                  Developer: Nihar R Paital
Close
              'Remove Message From Status Bar
              Application.StatusBar = False


       8 Click "File" and select "Close" to close the Visual Basic Editor.
       9 Click "Tools," select "Macro" and choose "Macros."
       10 Select the "ImportFile" macro from the "Macros" dialog box and click "Run."
       11 Enter the name of your file (myhugedocument.txt, for example) in the dialog box that appears.
       Excel will import the data, splitting it into multiple worksheets in order to circumvent Excel's line limit.




    3. Macro for removing un-necessary columns from a worksheet.
The below is the current contents of my worksheet. I want some of the columns out of the below columns.
Let say I want only Emp No, Emp Name, Emp DOB, EMP DOJ, Permanent Address. Except these all
other columns needs to be deleted.




   The below is the Procedure.

       1 Click "Tools," select "Macro" and choose "Macros."
       2 Type a name for your macro in the "Name" field, such as "DeleteUnWantedColumns" and click
       "Create." The Visual Basic Editor will open automatically.
       3 Double-click "(Name) Module" in the "Properties" window and type a name say "DeleteUnWanted"
       4 Click the "+" icon next to "Microsoft Excel Objects."
       5 Double-click "DeleteUnWanted" to open the "Code" window.
       6 Copy and paste the following into the "Code".

              Dim LASTCOL As Integer
              Dim J As Integer
              Dim DELETE_FLAG As Boolean
                LASTCOL = Cells(1, Columns.Count).End(xlToLeft).Column
                For J = LASTCOL To 1 Step -1
                  DELETE_FLAG = True
                  Select Case Cells(1, J)
                     Case "Emp No"
                        DELETE_FLAG = False
                     Case "Emp Name"
                                                                                    Developer: Nihar R Paital
DELETE_FLAG = False
              Case "Emp DOB"
                DELETE_FLAG = False
              Case "EMP DOJ"
                DELETE_FLAG = False
              Case "Permanent Address"
                DELETE_FLAG = False
              End Select
           If (DELETE_FLAG) Then Columns(J).Delete
         Next J

7 Save the Macro.
8 Click "Tools," select "Macro" and choose "Macros."
9 Select the "DeleteUnWantedColumns" macro from the "Macros" dialog box and click "Run."
This will delete all the unwanted columns. And the Output will as below.




                                                                     Developer: Nihar R Paital
4. Formula for finding matching values present in column A and
       Column B.
Follow the table below.
Here first two columns contain data. My requirement is “Which value of column A is present at Column
B.” and “which values of column A are not present at Column B.”




Write the function at C1 as =IF(COUNTIF($B$1:$B$9,A1:A9)=1,A1,"") for finding matching values. And
drag the formula up to C9.

Write the function at D1 as =IF(COUNTIF($B$1:$B$9,A1:A9)=0,A1,"") for finding the non-matching
values. And drag the formula up to D9.

The required Output table is as follows.


         1         7          1
         2         6                       2
         3         5                       3
         4         9          4
         5         1          5
         6        10          6
         7        12          7
         8        15                       8
         9         4          9




                                                                          Developer: Nihar R Paital
5. Formula for showing distinct values in a column.
Follow the table below.
Here first column A contains data. My requirement is “Finding out the distinct values within column A”




Write the function at B2 as =IF(MAX(COUNTIF(A2:A17,A2:A17))>1,"",A2) and drag it through B2 to
B18.
The required Output table is as follows.
Value        Distinct Value
         1
         2
         3
         4
         5            5
         3
        23           23
         3
         2
         1
         3
         4
         3
         1            1
         2            2
         3            3
         4            4
                                                 THANK YOU
                      (PS - Pls leave your ratings/feedback/comments on the main page)


                                                                              Developer: Nihar R Paital

Más contenido relacionado

La actualidad más candente

Creating a Microsoft Excel Macro
Creating a Microsoft Excel MacroCreating a Microsoft Excel Macro
Creating a Microsoft Excel MacroLauraly DuBois
 
Introduction to Excel VBA/Macros
Introduction to Excel VBA/MacrosIntroduction to Excel VBA/Macros
Introduction to Excel VBA/Macrosarttan2001
 
Using macros in microsoft excel part 1
Using macros in microsoft excel   part 1Using macros in microsoft excel   part 1
Using macros in microsoft excel part 1Er. Nawaraj Bhandari
 
Microsoft Office 2003 Creating Macros
Microsoft Office 2003 Creating MacrosMicrosoft Office 2003 Creating Macros
Microsoft Office 2003 Creating MacrosS Burks
 
Advance MS Excel
Advance MS ExcelAdvance MS Excel
Advance MS Excelacute23
 
E learning excel vba programming lesson 2
E learning excel vba programming  lesson 2E learning excel vba programming  lesson 2
E learning excel vba programming lesson 2Vijay Perepa
 
E learning excel vba programming lesson 1
E learning excel vba programming  lesson 1E learning excel vba programming  lesson 1
E learning excel vba programming lesson 1Vijay Perepa
 
Excel VBA programming basics
Excel VBA programming basicsExcel VBA programming basics
Excel VBA programming basicsHang Dong
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in Indiaibinstitute0
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3Vijay Perepa
 
VBA Classes from Chandoo.org - Course Brochure
VBA Classes from Chandoo.org - Course BrochureVBA Classes from Chandoo.org - Course Brochure
VBA Classes from Chandoo.org - Course Brochurer1c1
 
Intro to Excel VBA Programming
Intro to Excel VBA ProgrammingIntro to Excel VBA Programming
Intro to Excel VBA Programmingiveytechnologyclub
 

La actualidad más candente (20)

Microsoft Excel - Macros
Microsoft Excel - MacrosMicrosoft Excel - Macros
Microsoft Excel - Macros
 
Creating a Microsoft Excel Macro
Creating a Microsoft Excel MacroCreating a Microsoft Excel Macro
Creating a Microsoft Excel Macro
 
Introduction to Excel VBA/Macros
Introduction to Excel VBA/MacrosIntroduction to Excel VBA/Macros
Introduction to Excel VBA/Macros
 
Using macros in microsoft excel part 1
Using macros in microsoft excel   part 1Using macros in microsoft excel   part 1
Using macros in microsoft excel part 1
 
Microsoft Office 2003 Creating Macros
Microsoft Office 2003 Creating MacrosMicrosoft Office 2003 Creating Macros
Microsoft Office 2003 Creating Macros
 
Advance MS Excel
Advance MS ExcelAdvance MS Excel
Advance MS Excel
 
E learning excel vba programming lesson 2
E learning excel vba programming  lesson 2E learning excel vba programming  lesson 2
E learning excel vba programming lesson 2
 
E learning excel vba programming lesson 1
E learning excel vba programming  lesson 1E learning excel vba programming  lesson 1
E learning excel vba programming lesson 1
 
Vba introduction
Vba introductionVba introduction
Vba introduction
 
Vba Class Level 1
Vba Class Level 1Vba Class Level 1
Vba Class Level 1
 
Excel VBA programming basics
Excel VBA programming basicsExcel VBA programming basics
Excel VBA programming basics
 
Vba
Vba Vba
Vba
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3
 
Excel vba
Excel vbaExcel vba
Excel vba
 
VBA
VBAVBA
VBA
 
VBA Classes from Chandoo.org - Course Brochure
VBA Classes from Chandoo.org - Course BrochureVBA Classes from Chandoo.org - Course Brochure
VBA Classes from Chandoo.org - Course Brochure
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
 
Intro to Excel VBA Programming
Intro to Excel VBA ProgrammingIntro to Excel VBA Programming
Intro to Excel VBA Programming
 

Similar a Useful macros and functions for excel

Workbench tutorial airfoil
Workbench tutorial airfoilWorkbench tutorial airfoil
Workbench tutorial airfoilApriansyah Azis
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1rupeshkanu
 
Tutorials on Macro
Tutorials on MacroTutorials on Macro
Tutorials on MacroAnurag Deb
 
Tolerance Stackups Using Oracle Crystal Ball
Tolerance Stackups Using Oracle Crystal BallTolerance Stackups Using Oracle Crystal Ball
Tolerance Stackups Using Oracle Crystal BallRamon Balisnomo
 
OBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsOBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsDharmaraj Borse
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docxamrit47
 
( 13 ) Office 2007 Coding With Excel And Excel Services
( 13 ) Office 2007   Coding With Excel And Excel Services( 13 ) Office 2007   Coding With Excel And Excel Services
( 13 ) Office 2007 Coding With Excel And Excel ServicesLiquidHub
 
Spreadsheet Analytical Tools
Spreadsheet Analytical ToolsSpreadsheet Analytical Tools
Spreadsheet Analytical ToolsJoselito Perez
 
Learn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in DelhiLearn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in Delhiibinstitute0
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As CompDavid Halliday
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As CompDavid Halliday
 
Hw8Excel - Exercise 8 Mail Merge-2.docINFS 3250In Class Pro.docx
Hw8Excel - Exercise 8 Mail Merge-2.docINFS 3250In Class Pro.docxHw8Excel - Exercise 8 Mail Merge-2.docINFS 3250In Class Pro.docx
Hw8Excel - Exercise 8 Mail Merge-2.docINFS 3250In Class Pro.docxadampcarr67227
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxoscars29
 
Elementary Data Analysis with MS Excel_Day-4
Elementary Data Analysis with MS Excel_Day-4Elementary Data Analysis with MS Excel_Day-4
Elementary Data Analysis with MS Excel_Day-4Redwan Ferdous
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapaloozaJenniferBall44
 
Curve fitting
Curve fittingCurve fitting
Curve fittingdusan4rs
 

Similar a Useful macros and functions for excel (20)

Workbench tutorial airfoil
Workbench tutorial airfoilWorkbench tutorial airfoil
Workbench tutorial airfoil
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1
 
Tutorials on Macro
Tutorials on MacroTutorials on Macro
Tutorials on Macro
 
Tolerance Stackups Using Oracle Crystal Ball
Tolerance Stackups Using Oracle Crystal BallTolerance Stackups Using Oracle Crystal Ball
Tolerance Stackups Using Oracle Crystal Ball
 
Excel300
Excel300Excel300
Excel300
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
OBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsOBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation Steps
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docx
 
( 13 ) Office 2007 Coding With Excel And Excel Services
( 13 ) Office 2007   Coding With Excel And Excel Services( 13 ) Office 2007   Coding With Excel And Excel Services
( 13 ) Office 2007 Coding With Excel And Excel Services
 
Spreadsheet Analytical Tools
Spreadsheet Analytical ToolsSpreadsheet Analytical Tools
Spreadsheet Analytical Tools
 
Learn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in DelhiLearn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in Delhi
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
 
Visual basic bt0082
Visual basic  bt0082Visual basic  bt0082
Visual basic bt0082
 
Hw8Excel - Exercise 8 Mail Merge-2.docINFS 3250In Class Pro.docx
Hw8Excel - Exercise 8 Mail Merge-2.docINFS 3250In Class Pro.docxHw8Excel - Exercise 8 Mail Merge-2.docINFS 3250In Class Pro.docx
Hw8Excel - Exercise 8 Mail Merge-2.docINFS 3250In Class Pro.docx
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docx
 
Elementary Data Analysis with MS Excel_Day-4
Elementary Data Analysis with MS Excel_Day-4Elementary Data Analysis with MS Excel_Day-4
Elementary Data Analysis with MS Excel_Day-4
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
 
Curve fitting
Curve fittingCurve fitting
Curve fitting
 

Más de Nihar Ranjan Paital

Más de Nihar Ranjan Paital (11)

Oracle Select Query
Oracle Select QueryOracle Select Query
Oracle Select Query
 
Unix - Class7 - awk
Unix - Class7 - awkUnix - Class7 - awk
Unix - Class7 - awk
 
UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
 
UNIX - Class2 - vi Editor
UNIX - Class2 - vi EditorUNIX - Class2 - vi Editor
UNIX - Class2 - vi Editor
 
UNIX - Class1 - Basic Shell
UNIX - Class1 - Basic ShellUNIX - Class1 - Basic Shell
UNIX - Class1 - Basic Shell
 
UNIX - Class6 - sed - Detail
UNIX - Class6 - sed - DetailUNIX - Class6 - sed - Detail
UNIX - Class6 - sed - Detail
 
UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1
 
Test funda
Test fundaTest funda
Test funda
 
Csql for telecom
Csql for telecomCsql for telecom
Csql for telecom
 
Select Operations in CSQL
Select Operations in CSQLSelect Operations in CSQL
Select Operations in CSQL
 

Último

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Useful macros and functions for excel

  • 1. Useful Macros and functions for Excel This knowledge asset has information pertaining to Excel Macros and useful Functions. This document will let you know about some useful macros and functions, which are frequently used by the users. Topics Covered: 1. Macro for Deleting Blank columns from a worksheet................................................................................ 1 2. Macro uploading rows more than 65536. ................................................................................................... 2 3. Macro for removing un-necessary columns from a worksheet................................................................... 3 4. Formula for finding matching values present in column A and Column B................................................ 5 5. Formula for showing distinct values in a column. ...................................................................................... 6 Developer: Nihar R Paital
  • 2. 1. Macro for Deleting Blank columns from a worksheet. We need to delete the column B, E as they are blank. The below is the Procedure. 1 Click "Tools," select "Macro" and choose "Macros." 2 Type a name for your macro in the "Name" field, such as "DeleteBlankColumns" and click "Create." The Visual Basic Editor will open automatically. 3 Double-click "(Name) Module" in the "Properties" window and type a name say "DeleteBlankCol" 4 Click the "+" icon next to "Microsoft Excel Objects." 5 Double-click "DeleteBlankCol" to open the "Code" window. 6 Copy and paste the following into the "Code". Dim Col As Long, ColCnt As Long, Rng As Range Application.ScreenUpdating = False Application.Calculation = xlCalculationManual On Error GoTo Exits: If Selection.Columns.Count > 1 Then Set Rng = Selection Else Set Rng = Range(Columns(1), Columns(ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column())) End If ColCnt = 0 For Col = Rng.Columns.Count To 1 Step -1 If Application.WorksheetFunction.CountA(Rng.Columns(Col).EntireColumn) = 0 Then Rng.Columns(Col).EntireColumn.Delete ColCnt = ColCnt + 1 End If Next Col Exits: Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic 7 Save the Macro. 8 Click "Tools," select "Macro" and choose "Macros." 9 Select the "DeleteBlankColumns" macro from the "Macros" dialog box and click "Run." This will delete all the blank columns. Like B and E. Developer: Nihar R Paital
  • 3. 2. Macro uploading rows more than 65536. 1 Create a text file say myhugedocument.txt having number of lines more than 65536. 2 Click "Tools," select "Macro" and choose "Macros." 3 Type a name for your macro in the "Name" field, such as "ImportFile" and click "Create." The Visual Basic Editor will open automatically. 4 Double-click "(Name) Module" in the "Properties" window and type a name say "FileImport" 5 Click the "+" icon next to "Microsoft Excel Objects." 6 Double-click "FileImport" to open the "Code" window. 7 Copy and paste the following into the "Code". 'Dimension Variables Dim ResultStr As String Dim FileName As String Dim FileNum As Integer Dim Counter As Double 'Ask User for File's Name FileName = InputBox("Please enter the Text File's name, e.g. test.txt") 'Check for no entry If FileName = "" Then End 'Get Next Available File Handle Number FileNum = FreeFile() 'Open Text File For Input Open FileName For Input As #FileNum 'Turn Screen Updating Off Application.ScreenUpdating = False 'Create A New WorkBook With One Worksheet In It Workbooks.Add template:=xlWorksheet 'Set The Counter to 1 Counter = 1 'Loop Until the End Of File Is Reached Do While Seek(FileNum) <= LOF(FileNum) 'Display Importing Row Number On Status Bar Application.StatusBar = "Importing Row " & _ Counter & " of text file " & FileName 'Store One Line Of Text From File To Variable Line Input #FileNum, ResultStr 'Store Variable Data Into Active Cell If Left(ResultStr, 1) = "=" Then ActiveCell.Value = "'" & ResultStr Else ActiveCell.Value = ResultStr End If 'For Excel versions before Excel 97, change 65536 to 16384 If ActiveCell.Row = 65536 Then 'If On The Last Row Then Add A New Sheet ActiveWorkbook.Sheets.Add Else 'If Not The Last Row Then Go One Cell Down ActiveCell.Offset(1, 0).Select End If 'Increment the Counter By 1 Counter = Counter + 1 'Start Again At Top Of 'Do While' Statement Loop 'Close The Open Text File Developer: Nihar R Paital
  • 4. Close 'Remove Message From Status Bar Application.StatusBar = False 8 Click "File" and select "Close" to close the Visual Basic Editor. 9 Click "Tools," select "Macro" and choose "Macros." 10 Select the "ImportFile" macro from the "Macros" dialog box and click "Run." 11 Enter the name of your file (myhugedocument.txt, for example) in the dialog box that appears. Excel will import the data, splitting it into multiple worksheets in order to circumvent Excel's line limit. 3. Macro for removing un-necessary columns from a worksheet. The below is the current contents of my worksheet. I want some of the columns out of the below columns. Let say I want only Emp No, Emp Name, Emp DOB, EMP DOJ, Permanent Address. Except these all other columns needs to be deleted. The below is the Procedure. 1 Click "Tools," select "Macro" and choose "Macros." 2 Type a name for your macro in the "Name" field, such as "DeleteUnWantedColumns" and click "Create." The Visual Basic Editor will open automatically. 3 Double-click "(Name) Module" in the "Properties" window and type a name say "DeleteUnWanted" 4 Click the "+" icon next to "Microsoft Excel Objects." 5 Double-click "DeleteUnWanted" to open the "Code" window. 6 Copy and paste the following into the "Code". Dim LASTCOL As Integer Dim J As Integer Dim DELETE_FLAG As Boolean LASTCOL = Cells(1, Columns.Count).End(xlToLeft).Column For J = LASTCOL To 1 Step -1 DELETE_FLAG = True Select Case Cells(1, J) Case "Emp No" DELETE_FLAG = False Case "Emp Name" Developer: Nihar R Paital
  • 5. DELETE_FLAG = False Case "Emp DOB" DELETE_FLAG = False Case "EMP DOJ" DELETE_FLAG = False Case "Permanent Address" DELETE_FLAG = False End Select If (DELETE_FLAG) Then Columns(J).Delete Next J 7 Save the Macro. 8 Click "Tools," select "Macro" and choose "Macros." 9 Select the "DeleteUnWantedColumns" macro from the "Macros" dialog box and click "Run." This will delete all the unwanted columns. And the Output will as below. Developer: Nihar R Paital
  • 6. 4. Formula for finding matching values present in column A and Column B. Follow the table below. Here first two columns contain data. My requirement is “Which value of column A is present at Column B.” and “which values of column A are not present at Column B.” Write the function at C1 as =IF(COUNTIF($B$1:$B$9,A1:A9)=1,A1,"") for finding matching values. And drag the formula up to C9. Write the function at D1 as =IF(COUNTIF($B$1:$B$9,A1:A9)=0,A1,"") for finding the non-matching values. And drag the formula up to D9. The required Output table is as follows. 1 7 1 2 6 2 3 5 3 4 9 4 5 1 5 6 10 6 7 12 7 8 15 8 9 4 9 Developer: Nihar R Paital
  • 7. 5. Formula for showing distinct values in a column. Follow the table below. Here first column A contains data. My requirement is “Finding out the distinct values within column A” Write the function at B2 as =IF(MAX(COUNTIF(A2:A17,A2:A17))>1,"",A2) and drag it through B2 to B18. The required Output table is as follows. Value Distinct Value 1 2 3 4 5 5 3 23 23 3 2 1 3 4 3 1 1 2 2 3 3 4 4 THANK YOU (PS - Pls leave your ratings/feedback/comments on the main page) Developer: Nihar R Paital