Compile Error: Next Without For Error - Need Help Please :)

tatertot

New Member
Joined
Apr 10, 2016
Messages
31
I am using the code below to find any cells in the designated range that have "yes" or "no". In doing so, i was wanting to supply some special formatting for each instance.

Issue is I am receiving a "Compile Error: Next Without for Error". Could anyone tell me what I am doing wrong to resolve this issue??


Code:
Sub ValidateAuditData()

'Create macro to validate the input data


Dim AuditRange As Range
Set AuditRange = Worksheets("Sheet1").Range("A6:D199")


AuditRange.SpecialCells(xlCellTypeBlanks).Interior.ColorIndex = 6


'Create code to remove fill


For Each cell In AuditRange


If cell.Value = "Yes" Then
    cell.Interior.ColorIndex = 4
    cell.Font.Bold
If cell.Value = "No" Then
    cell.Interior.ColorIndex = 3
    cell.Font.Bold
    Next


End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Add two End if Statements as below

Code:
If cell.Value = "Yes" Then
    cell.Interior.ColorIndex = 4
    cell.Font.Bold
If cell.Value = "No" Then
    cell.Interior.ColorIndex = 3
    cell
End if
End if
Next
 
Upvote 0
Hi Alan,

Thanks for the suggestion! When I added the code to my macro I get the following error:

"Run-time error'1004: Bold Method of font class failed"

Suggestion for correcting?
 
Upvote 0
try this modification of your code

Code:
Option Explicit


Sub ValidateAuditData()
Dim cell As Range
'Create macro to validate the input data




Dim AuditRange As Range
Set AuditRange = Worksheets("Sheet1").Range("A6:D16")




'AuditRange.SpecialCells(xlCellTypeBlanks).Interior.ColorIndex = 6




'Create code to remove fill




For Each cell In AuditRange




If cell.Value = "Yes" Then
    cell.Interior.ColorIndex = 4
    cell.Font.Bold = True
ElseIf cell.Value = "No" Then
    cell.Interior.ColorIndex = 3
    cell.Font.Bold = True
End If
    Next


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top