Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA code to make command button results bold

Posted on 2009-04-04
4
Medium Priority
?
536 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 500 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

886 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