Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Next without For error

I get the following error, "Next without For". How do I change my code to
fix it?

'Format Colums which are John
For a = 4 To 31
If Cells(a, 1).Value = "John" Then
For b = 2 To 32
If Cells(2, b).Value = "Fri" Then
Cells(a, b).Select
With Selection.Interior
.ColorIndex = 0
.Pattern = xlGray8
.PatternColorIndex = xlAutomatic
End With
Next b
End If
Next a

MsgBox "Formatting Complete"
Exit Sub
Error:
Exit Sub
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Next without For error

Wasn't this answered comprehensively yesterday???

--

Vasant

"John Keturi" wrote in message
news:O8vvc.42031$mm1.13316@fed1read06...
I get the following error, "Next without For". How do I change my code to
fix it?

'Format Colums which are John
For a = 4 To 31
If Cells(a, 1).Value = "John" Then
For b = 2 To 32
If Cells(2, b).Value = "Fri" Then
Cells(a, b).Select
With Selection.Interior
.ColorIndex = 0
.Pattern = xlGray8
.PatternColorIndex = xlAutomatic
End With
Next b
End If
Next a

MsgBox "Formatting Complete"
Exit Sub
Error:
Exit Sub
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Next without For error

John,

It looks like you need an enf if after next a


Charle

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Next without For error

Hi John,

Responding to your error, and not otherwise looking at your code, you need
to insert:
End If
after your:
End With

---
Regards,
Norman

"John Keturi" wrote in message
news:O8vvc.42031$mm1.13316@fed1read06...
I get the following error, "Next without For". How do I change my code to
fix it?

'Format Colums which are John
For a = 4 To 31
If Cells(a, 1).Value = "John" Then
For b = 2 To 32
If Cells(2, b).Value = "Fri" Then
Cells(a, b).Select
With Selection.Interior
.ColorIndex = 0
.Pattern = xlGray8
.PatternColorIndex = xlAutomatic
End With
Next b
End If
Next a

MsgBox "Formatting Complete"
Exit Sub
Error:
Exit Sub
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Next without For error

Norman's answer is correct. This is a good example of why it's good t
use indentation in your code listing -- it makes it much easier to spo
these kinds of "out of balance" type errors. See indented code below
Also suggest that you not use VB keywords, like "Error" as labels
Finally, you likely realize that your your last "exit Sub" i
unnecessary but doesn't do any real harm; perhaps you included it jus
to make the code a bit more explicit, and thus clearer -- not a ba
idea.

'Format Colums which are John
Sub test()
On Error GoTo ErrHandler:
For a = 4 To 31
If Cells(a, 1).Value = "John" Then
For b = 2 To 32
If Cells(2, b).Value = "Fri" Then
Cells(a, b).Select
With Selection.Interior
.ColorIndex = 0
.Pattern = xlGray8
.PatternColorIndex = xlAutomatic
End With
End If
Next b
End If
Next a
MsgBox "Formatting Complete"
Exit Sub
ErrHandler:
Exit Sub
End Sub

Regards,
billly

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Next without For error

I just realized that this board doesn't show the indentations in the
code. Sorry for that, but I think you'll get the idea.

billyb


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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Automation Error, Unknown Error. Error value - 440 Neo[_2_] Excel Programming 0 May 29th 04 05:26 AM
Error 50290: Error writing to Worksheet while using an ActiveX Control emblair3 Excel Programming 3 February 24th 04 06:03 PM


All times are GMT +1. The time now is 07:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"