+ Reply to Thread
Results 1 to 5 of 5

Call one function from another function in excel VBA

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    231

    Call one function from another function in excel VBA

    Hello All,

    I have 2 functions in my excel VBA.

    1. Sub InsertPivotTable() - This function is creating pivot table in a new worksheet. Sheet B

    2. Sub Copy_Pivot() - This function is copying pivot table from new sheet B to existing Sheet A.

    Both the functions are working fine separately. But I have 2 macros for this.

    Is there a way I can call Copy_Pivot() in the InsertPivotTable() function.

    I added 'Copy_Pivot' towards the end. But this is not working and adding the function is not creating pivot table even.

    Can any one please let me know what is missing here.


    Sub InsertJEPivotTable()
    
    code
    ActiveSheet.PivotTables("SalesPivotTable").PivotFields("DR Amount").Subtotals = Array( _
            False, False, False, False, False, False, False, False, False, False, False, False)
            
    Copy_Pivot
    
    End Sub

  2. #2
    Registered User
    Join Date
    12-31-2022
    Location
    India
    MS-Off Ver
    2013
    Posts
    9

    Re: Call one function from another function in excel VBA

    Just copy paste the codes you used inside the sub Copy_Pivot() macro ,to the end of the Sub InsertPivotTable() . It will work .!

  3. #3
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    231

    Re: Call one function from another function in excel VBA

    Hello,

    Thanks for the reply. I tried giving the code in the main sub. But it did not work. This is the code to copy pivot from 'PivotTable' sheet to 'Check' sheet.

    Worksheets("Check").Activate
    Range("B11:D9999").Select
        Selection.ClearContents
        Sheets("PivotTable").Select
        ActiveSheet.PivotTables("SalesPivotTable").PivotSelect "'Company Code'[All]", _
            xlLabelOnly, True
        Range("B11:D9999").Select
        Selection.Copy
        Sheets("Check").Select
        Range("B11").Select
        ActiveSheet.Paste
        Range("D12").Select

  4. #4
    Forum Contributor
    Join Date
    04-16-2020
    Location
    Alberta, Canada
    MS-Off Ver
    365
    Posts
    230

    Re: Call one function from another function in excel VBA

    Make them functions, not subs on specific work sheets.

  5. #5
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    231

    Re: Call one function from another function in excel VBA

    Hello, Thanks for the reply.

    Can you please let me know what the return value would be if I make it a function instead of Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Delineating recursive function call in emulation code of worksheet SUM function
    By hic24 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2021, 10:27 AM
  2. Replies: 2
    Last Post: 06-03-2014, 03:44 AM
  3. Cannot call function VBA in excel 2010. Please help me.
    By huynhpa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2013, 05:20 AM
  4. how to call a function in excel VBA through VBS?
    By its_you in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2007, 08:13 AM
  5. call a excel function from a vb project
    By Alex281 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2006, 12:30 AM
  6. [SOLVED] Help with VB Call function from Excel
    By Lawrence M. Seldin, CMC, CPC in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-03-2005, 02:05 PM
  7. call outlook's function from excel
    By MrGutis in forum Excel General
    Replies: 0
    Last Post: 03-23-2005, 08:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1