ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA - Formatting issue.... (https://www.excelbanter.com/excel-programming/299832-vba-formatting-issue.html)

donmiller23

VBA - Formatting issue....
 
I'm trying to get only certain cells to BOLD, but am running int
problems.

So far, I have the following:


Application.Run "'Part D-1 Regular.xls'!Unprotect_Sheet_Password"
Sheets("April").Select
If Range("O17") = "Bold" Then
Range("C17").Select
Selection.Font.Bold = True
ElseIf Range("O18") = "Bold" Then
Range("C18").Select
Selection.Font.Bold = True
ElseIf Range("O19") = "Bold" Then
Range("C19").Select
Selection.Font.Bold = True
ElseIf Range("O20") = "Bold" Then
Range("C20").Select
Selection.Font.Bold = True
Else
MsgBox "No Other Payor Sources to be Bold!"
End If
End Sub

If cell O18 doesn't say "BOLD" the script stops even if cell O19 doe
say "BOLD"

This is driving me crazy, I've also tried changing "ElseIf" to jus
"If" but it still runs into the same problem.

what am i doing wrong

--
Message posted from http://www.ExcelForum.com


pikus

VBA - Formatting issue....
 
If Range("O17").Value = "Bold" Then

Apply that change to each IF statement. - Piku

--
Message posted from http://www.ExcelForum.com


Frank Kabel

VBA - Formatting issue....
 
Hi
try the following:
sub foo()
dim row_index as long
Application.Run "'Part D-1 Regular.xls'!Unprotect_Sheet_Password"
for row_index = 17 to 20
with activesheet.cells(row_index,"O")
if .value = "Bold" then
.offset(0,-12).font.bold=true
end if
end with
next
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany


I'm trying to get only certain cells to BOLD, but am running into
problems.

So far, I have the following:


Application.Run "'Part D-1 Regular.xls'!Unprotect_Sheet_Password"
Sheets("April").Select
If Range("O17") = "Bold" Then
Range("C17").Select
Selection.Font.Bold = True
ElseIf Range("O18") = "Bold" Then
Range("C18").Select
Selection.Font.Bold = True
ElseIf Range("O19") = "Bold" Then
Range("C19").Select
Selection.Font.Bold = True
ElseIf Range("O20") = "Bold" Then
Range("C20").Select
Selection.Font.Bold = True
Else
MsgBox "No Other Payor Sources to be Bold!"
End If
End Sub

If cell O18 doesn't say "BOLD" the script stops even if cell O19 does
say "BOLD"

This is driving me crazy, I've also tried changing "ElseIf" to just
"If" but it still runs into the same problem.

what am i doing wrong?


---
Message posted from http://www.ExcelForum.com/



donmiller23[_2_]

VBA - Formatting issue....
 
i've tried

If Range("O17").Value = "Bold" Then

but it still stops @ cell C18 (the cell w/o "Bold")

--
Message posted from http://www.ExcelForum.com


pikus

VBA - Formatting issue....
 
Do you realize that using If...ElseIf means that the code will sto
after the first time that condition evaluates to true? You could d
something like this:

For x = 17 To 20
If Worksheets("April").Cells(x, 15).Value = "BOLD" Then
Worksheets("April").Cells(x, 3).Font.Bold = True
End If
Next x

- Piku

--
Message posted from http://www.ExcelForum.com


donmiller23[_3_]

VBA - Formatting issue....
 
this works, but I need to go all the way to row 174

--
Message posted from http://www.ExcelForum.com


pikus

VBA - Formatting issue....
 
For x = 17 To 174
If Worksheets("April").Cells(x, 15).Value = "BOLD" Then
Worksheets("April").Cells(x, 3).Font.Bold = True
End If
Next

--
Message posted from http://www.ExcelForum.com


donmiller23[_4_]

VBA - Formatting issue....
 
I also need to use this for May through March (the 11 other worksheets)
How would I go about implementing this change

--
Message posted from http://www.ExcelForum.com


Frank Kabel

VBA - Formatting issue....
 
Hi
missd that part :-) Though you could also use then:
sub foo()
dim row_index as long
Application.Run "'Part D-1 Regular.xls'!Unprotect_Sheet_Password"
for row_index = 17 to 200
with activesheet.cells(row_index,"O")
if .value = "Bold" then
.offset(0,-12).font.bold=true
exit for
end if
end with
next
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany


Do you realize that using If...ElseIf means that the code will stop
after the first time that condition evaluates to true? You could do
something like this:

For x = 17 To 20
If Worksheets("April").Cells(x, 15).Value = "BOLD" Then
Worksheets("April").Cells(x, 3).Font.Bold = True
End If
Next x

- Pikus


---
Message posted from http://www.ExcelForum.com/


pikus

VBA - Formatting issue....
 
For z = 1 To 12
For x = 17 To 174
If Worksheets(MonthName(z)).Cells(x, 15).Value = "BOLD" Then
Worksheets(MonthName(z)).Cells(x, 3).Font.Bold = True
End If
Next x
Next

--
Message posted from http://www.ExcelForum.com


pikus

VBA - Formatting issue....
 
This is better...

Application.ScreenUpdating = False
For z = 1 To 12
With Worksheets(MonthName(z))
For x = 17 To 174
If .Cells(x, 15).Value = "BOLD" Then
.Cells(x, 3).Font.Bold = True
End If
Next x
End With
Next z
Application.ScreenUpdating = True

That should be a bit faster. - Piku

--
Message posted from http://www.ExcelForum.com


donmiller23[_5_]

VBA - Formatting issue....
 
Great! This works, no problem. Thanks guys

--
Message posted from http://www.ExcelForum.com


pikus

VBA - Formatting issue....
 
:-

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 10:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com