Solved

VBA code to make command button results bold

Posted on 2009-04-04
4
518 Views
Last Modified: 2013-11-25
In the code below I would like to add a command to make the formula results and the  text (total hours) to be in bold.
Private Sub CommandButton1_Click()
 

Dim lrow As Long

lrow = Cells(65536, "C").End(xlUp).Row

Cells(lrow + 2, "I").Formula = "=sum(I16:I" & lrow & ")"

Cells(lrow + 2, "J").Formula = "=sum(J16:J" & lrow & ")"

Cells(lrow + 2, "K").Formula = "=sum(K16:K" & lrow & ")"

Cells(lrow + 2, "L").Formula = "=sum(L16:L" & lrow & ")"

Cells(lrow + 2, "M").Formula = "=sum(M16:M" & lrow & ")"

Cells(lrow + 2, "N").Formula = "=sum(N16:N" & lrow & ")"

Cells(lrow + 2, "O").Formula = "=sum(O16:O" & lrow & ")"

Cells(lrow + 2, "F") = "Total Hours"

End Sub

Open in new window

0
Comment
Question by:RRUTLAND5
  • 3
4 Comments
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 24068665
you can make the results bold in the same command button click procedure above. however if you want it in a separate command button, the code is here below
      


Private Sub CommandButton2_Click()

 

Dim lrow As Long

lrow = Cells(65536, "C").End(xlUp).Row

Cells(lrow + 2, "I").Font.Bold=True

Cells(lrow + 2, "J").Font.Bold=True

Cells(lrow + 2, "K").Font.Bold=True

Cells(lrow + 2, "L").Font.Bold=True

Cells(lrow + 2, "M").Font.Bold=True

Cells(lrow + 2, "N").Font.Bold=True

Cells(lrow + 2, "O").Font.Bold=True

Cells(lrow + 2, "F").Font.Bold=True

End Sub

Open in new window

0
 

Author Comment

by:RRUTLAND5
ID: 24069524
How can I do it in the same command button procedure?
0
 
LVL 13

Accepted Solution

by:
hiteshgoldeneye earned 125 total points
ID: 24070062
here is how


Private Sub CommandButton1_Click()

 

Dim lrow As Long

lrow = Cells(65536, "C").End(xlUp).Row

Cells(lrow + 2, "I").Formula = "=sum(I16:I" & lrow & ")"

Cells(lrow + 2, "J").Formula = "=sum(J16:J" & lrow & ")"

Cells(lrow + 2, "K").Formula = "=sum(K16:K" & lrow & ")"

Cells(lrow + 2, "L").Formula = "=sum(L16:L" & lrow & ")"

Cells(lrow + 2, "M").Formula = "=sum(M16:M" & lrow & ")"

Cells(lrow + 2, "N").Formula = "=sum(N16:N" & lrow & ")"

Cells(lrow + 2, "O").Formula = "=sum(O16:O" & lrow & ")"

Cells(lrow + 2, "F") = "Total Hours"

Cells(lrow + 2, "I").Font.Bold=True

Cells(lrow + 2, "J").Font.Bold=True

Cells(lrow + 2, "K").Font.Bold=True

Cells(lrow + 2, "L").Font.Bold=True

Cells(lrow + 2, "M").Font.Bold=True

Cells(lrow + 2, "N").Font.Bold=True

Cells(lrow + 2, "O").Font.Bold=True

Cells(lrow + 2, "F").Font.Bold=True
 

End Sub

Open in new window

0
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 24075216
A better approach would be as below
Private Sub CommandButton1_Click()

 

Dim lrow As Long

lrow = Cells(65536, "C").End(xlUp).Row

Cells(lrow + 2, "I").Formula = "=sum(I16:I" & lrow & ")"

Cells(lrow + 2, "J").Formula = "=sum(J16:J" & lrow & ")"

Cells(lrow + 2, "K").Formula = "=sum(K16:K" & lrow & ")"

Cells(lrow + 2, "L").Formula = "=sum(L16:L" & lrow & ")"

Cells(lrow + 2, "M").Formula = "=sum(M16:M" & lrow & ")"

Cells(lrow + 2, "N").Formula = "=sum(N16:N" & lrow & ")"

Cells(lrow + 2, "O").Formula = "=sum(O16:O" & lrow & ")"

Cells(lrow + 2, "F") = "Total Hours"

Range("I" & lrow + 2 & ":O" & lrow + 2).Font.Bold=True

Cells(lrow + 2, "F").Font.Bold=True

 

End Sub

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

760 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

21 Experts available now in Live!

Get 1:1 Help Now