Using a Macro as a Function Called From Cell to Populate a Cell Value

Using a Macro as a Function Called From Cell to Populate a Cell Value

I'm trying to populate individual cells with  function calls to a macro similar to how one would use a regular function to populate a cell. My function is:

Public Function getHours(item As String,high As Number) As Double
    Sheets("Work Items").Select
    numRows = ActiveSheet.Rows
    getHours = 0

    For i = 2 To numRows
        if Cells(i,2).value= item Then
            if high = 1 Then   
                getHours = getHours + Cells(i,6).value
                getHours = getHours + Cells(i,5).value
            end if
          end if
    Next i
End Function      

Where I pass a cell value and constant to return a double. However, whenever I try to use the function, it doesn't come up as an option when I type = into the cell, and when I type out the arguments like "=getHours(a3,0)", it re-formats to "=GETHOURS(A3;0)" and gives me a #NAME! error. Even if my code isn't correct, it doesn't seem like using macros in this fashion even works in Sheet.

My function doesn't show up on the manage tab for macros, but when I try to create a new macro with the same name it says that it already exists.

If using a macro isn't possible, could I be assisted with an alternative method?


    • Sticky Posts

    • Announcing IMPORTRANGE and cross-spreadsheet linking in Zoho Sheet

      We are pleased to announce the much-requested IMPORTRANGE function in Zoho Sheet. With this function, you can now link or refer to cell ranges across spreadsheets in an instant.   Refer across spreadsheets You can use IMPORTRANGE just like any other predefined function in Zoho Sheet. Start with an equal sign, select the function, and fill in the parameters. For this function, the source spreadsheet link and the desired cell range to import are given as input.     Once you allow access to the source
    • Tab Colors and New Currency Symbol of Indian Rupee

      Zoho Sheet has recently added support for the following 2 new features: Tab Colors: Since last month, you can set a color to your worksheet tabs. Use colors to quickly identify/highlight specific worksheets or to group similar worksheets together. This option is available on the right click context menu of the worksheet tab. Add color to your worksheets! Indian Rupee Currency - New Symbol: The new Indian Rupee Symbol, ₹, is now supported in Zoho Sheet. This replaces the old "Rs." currency symbol
    • Expanding and securing ways to share your spreadsheet: email as attachment and password protection

      While Zoho Sheet allows you to share and collaborate with your colleagues in real time, you might wish to send your spreadsheets as email attachments or keep an offline version of a confidential file with password protection. Here's how our new options
    • Display text the preferred way with text rotation, indent, and wrapping options

      Working with long, textual data in spreadsheets just got better! Zoho Sheet now supports text rotation, indentation, and wrapping options, which you can use to display the text and other values in your spreadsheet exactly the way you want.   Set the right
    • Dark mode in Zoho Sheet—Work with comfort, night or day

      With working from home becoming more and more common this last year, we at Zoho Sheet understand that conventional working hours for many people across the globe have changed. That's why we're pleased to say we're making it easier for our users to work

            Zoho DataPrep Resources

                Zoho CRM Plus Resources

                  Zoho Books Resources

                    Zoho Subscriptions Resources

                      Zoho Desk Resources

                        Zoho Projects Resources

                          Zoho Sprints Resources

                            Zoho Orchestly Resources

                              Zoho Creator Resources

                                Zoho WorkDrive Resources

                                    Zoho Campaigns Resources

                                      Zoho CRM Resources

                                                  Design. Discuss. Deliver.

                                                  Create visually engaging stories with Zoho Show.

                                                  Get Started Now

                                                      Zoho Writer Writer

                                                      Get Started. Write Away!

                                                      Writer is a powerful online word processor, designed for collaborative work.