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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,216,175
Messages
6,129,312
Members
449,500
Latest member
Jacky Son

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