![]() |
Summing Cells and Formatting
1.) How do I change the TextBox21 line of code to make it
sum the cells A4, A9, E4, AND E9? Private Sub CommandButton1_click() With UserForm2 .TextBox21.Value = Application.Sum(Cells ("A4", "A9", "E4", "E9")) .Show End With End Sub 2.) For TextBox21, what would the code be to: a. make the value percentage, and b. make the font bold/red when the value is not 100%? Thanks, Phil |
Summing Cells and Formatting
Phil,
I think this does it all for you Private Sub CommandButton1_click() Dim rng As Range Dim nValue As Double Set rng = Range("A4, A9, E4, E9") nValue = Application.Sum(rng) With UserForm2 With .TextBox21 .Value = Format(nValue, "0%") If nValue = 1 Then .Font.Bold = True .ForeColor = RGB(&HFF, &H0, &H0) Else .Font.Bold = False .ForeColor = RGB(&H0, &H0, &H0) End If End With .Show End With End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Phil Hageman" wrote in message ... 1.) How do I change the TextBox21 line of code to make it sum the cells A4, A9, E4, AND E9? Private Sub CommandButton1_click() With UserForm2 .TextBox21.Value = Application.Sum(Cells ("A4", "A9", "E4", "E9")) .Show End With End Sub 2.) For TextBox21, what would the code be to: a. make the value percentage, and b. make the font bold/red when the value is not 100%? Thanks, Phil |
All times are GMT +1. The time now is 06:26 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com