VBA Summing a Table Inside of a UserForm

Alright I've been at this workbook for 15 hours today and I didn't expect this to fight me... but it is. What's the correct Syntax to Sum and entire table's column in VBA for a field in my userform?

Private Sub drpFHInputMethod_Change()
    If drpFHInputMethod.Value = "From Planning Dashboard" Then
        txtReqFH.Value = Application.WorksheetFunction.Sum(TableFHAnalysisEngine[ApprovedHours])
        txtReqFH.Locked = True
        OptionButtonYes.SetFocus
    Else: txtReqFH.Locked = False
        txtReqFH.Value = ""
        txtReqFH.SetFocus
    End If
End Sub

Open in new window

LVL 1
-PolakAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
The easiest way would be to make use of the Table's Total Row assuming you are referring to a Data table. This is untested but attach an example workbook and I'll lcheck it for you

 Dim oTbl As ListObject
    Dim TotalsOn As Boolean
    Set oTbl = ActiveSheet.ListObjects("TableFHAnalysisEngine")
    With oTbl.ShowTotals
        TotalsOn = .ShowTotals
        If .ShowTotals = False Then .ShowTotals = True
        .ListColumns("ApprovedHours").TotalsCalculation = _
        xlTotalsCalculationSum
        MsgBox .Range("TableFHAnalysisEngine[[#Totals],[ApprovedHours]").Value
        .ShowTotals = TotalsOn
    End With

Open in new window

-PolakAuthor Commented:
That threw aCapture.JPG for me. Here's a dummy workbook. Honestly if the best/easiest way is to just have a backendsheet do the worksheet calculation and then pass that value into the  User form I'm not opposed(if you look at my code a bunch of the other buttons already use a backend sheet).... I just thought it would be simple to do this all in VBA.
VBAUSerFormSumming.xlsm
Martin LissOlder than dirtCommented:
In your workbook the table name is Table1 and this works.

Private Sub drpFHInputMethod_Change()
    If drpFHInputMethod.Value = "From Planning Dashboard" Then
        txtReqFH.Value = Application.WorksheetFunction.Sum(ActiveSheet.ListObjects("Table1").ListColumns("ApprovedHours").Range)
      
        txtReqFH.Locked = True
        OptionButtonYes.SetFocus
    Else: txtReqFH.Locked = False
        txtReqFH.Value = ""
        txtReqFH.SetFocus
    End If
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
-PolakAuthor Commented:
(looks like I forgot to rename) Nice! I just learned about DatabodyRange and xlCellTypeVisible yesterday. Infact, that's how "Table 1" gets its data in the first place in the real workbook.
Martin LissOlder than dirtCommented:
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.