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

Hi

I have atempted to write the code below which should check
Range I3 to I1000 and if there is no "Y" in the cell to
copy the sheet (name held in the offset(0,-2)) to a wb
which is determined by the Case Select Statement.

The code is being stopped with the error message "Compile
Error - Next without For"

Is the to do with me embedding either the IF or CASE
SELECT stament inside the For Next loop?

TIA


Sub Copy_Sheets()
Dim shName As Range
Dim prName As Range
Dim CValue As Range

rng = Columns("I3:I1000")

With Worksheets("Index")
For Each cell In rng

If rng = "Y" Then
shName = cell.Offset(0, -2).Value
prName = cell.Offset(0, -1).Value
CValue = cell.Offset(0, 1)

Select Case prName
Case "Austravel"
prloc = "S:\Kingston\FA\Overseas Payments\Overseas
Payments Public\Remittance\Long Haul\Austravel\Austravel
Crystal Export File.xls"
Case "Tropical"
prloc = "S:\Kingston\FA\Ove0rseas Payments\Overseas
Payments Public\Remittance\Long Haul\Tropical\Tropical
Crystal Export File.xls"
Case "Jetsave"
prloc = "S:\Kingston\FA\Overseas Payments\Overseas
Payments Public\Remittance\Long Haul\Jetsave\Jetsave
Crystal Export File.xls"
End Select

Sheets(shName).Copy After:=Workbooks(prloc).Worksheet.Count
cell = "Y"

Next cell
Else
Next cell
End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error with For Next

Edgar,

Haven't checked the logic, but your If doesn't end.

Replace this

Next cell
Else
Next cell

with

Next Cell
End If

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Edgar" wrote in message
...
Hi

I have atempted to write the code below which should check
Range I3 to I1000 and if there is no "Y" in the cell to
copy the sheet (name held in the offset(0,-2)) to a wb
which is determined by the Case Select Statement.

The code is being stopped with the error message "Compile
Error - Next without For"

Is the to do with me embedding either the IF or CASE
SELECT stament inside the For Next loop?

TIA


Sub Copy_Sheets()
Dim shName As Range
Dim prName As Range
Dim CValue As Range

rng = Columns("I3:I1000")

With Worksheets("Index")
For Each cell In rng

If rng = "Y" Then
shName = cell.Offset(0, -2).Value
prName = cell.Offset(0, -1).Value
CValue = cell.Offset(0, 1)

Select Case prName
Case "Austravel"
prloc = "S:\Kingston\FA\Overseas Payments\Overseas
Payments Public\Remittance\Long Haul\Austravel\Austravel
Crystal Export File.xls"
Case "Tropical"
prloc = "S:\Kingston\FA\Ove0rseas Payments\Overseas
Payments Public\Remittance\Long Haul\Tropical\Tropical
Crystal Export File.xls"
Case "Jetsave"
prloc = "S:\Kingston\FA\Overseas Payments\Overseas
Payments Public\Remittance\Long Haul\Jetsave\Jetsave
Crystal Export File.xls"
End Select

Sheets(shName).Copy After:=Workbooks(prloc).Worksheet.Count
cell = "Y"

Next cell
Else
Next cell
End With

End Sub



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
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
I have Error 1919 Error Configuring ODBC dataSource Database Texanna1 Excel Discussion (Misc queries) 1 September 12th 06 06:35 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM


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

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

About Us

"It's about Microsoft Excel"