Solved

VBA code to make command button results bold

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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