Solved

VBA code to make command button results bold

Posted on 2009-04-04
4
527 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

820 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