Solved

VBA code to make command button results bold

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

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 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

16 Experts available now in Live!

Get 1:1 Help Now