Excel VBA Updating existing text label

Posted on 2007-03-26
Last Modified: 2010-04-30
Hi all

I'm attempting to update a text label with a subtotal formula.  I'd like to do it without relying on VBA, but I'll take what I can get.  Subtotal will update anytime an autofilter criteria is changed, so I'd like to rely on that to change my label, but I can figure out how to do it outside a procedure, which follows:

Sub Calc_Subtotals()
    Application.ScreenUpdating = False

    With Sheet12.Subtotal_lbl
    .Caption = Range("D6").Text
    End With

    Application.ScreenUpdating = True
End Sub

Thanks for any suggestions!

Question by:bfreescott
  • 2
LVL 81

Accepted Solution

byundt earned 250 total points
ID: 18797721
I assume that you want to change the caption on a command button or the like. If so, you can take advantage of the fact that the Calculate event sub runs whenever you use the AutoFilter and thereby change the value in a SUBTOTAL formula. Try the following sub in the codepane of the worksheet containing your AutoFilter.

Private Sub Worksheet_Calculate()
With Sheet12.Subtotal_lbl
      .Caption = Range("D6").Text
End With
End Sub


Author Comment

ID: 18798247
That did the trick!  Thanks Brad!
LVL 81

Expert Comment

ID: 18799249
Thanks for the grade!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now