LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ray Ray is offline
external usenet poster
 
Posts: 267
Default Next without For? can't find the problem

Hope someone with 'eagle eyes' can help on this one ...

Here's my code:
Sub UpdStoData_Click()
Dim Path As String, stonum As String, FilesInPath As String
Dim MyFiles() As String, Trange As String, Tcol As Integer
Dim SourceRcount As Long, x As Long, Fnum As Long, total As Long
Dim mybook As Workbook, basebook As Workbook, ws As Worksheet, Sh
As String
Dim sourceRange As Range, destrange As Range, myC As Range

Path = "\\Retus100-nt0009\common\US OPS Projects\from Stores\"

'Add a slash at the end if the user forget it
If Right(Path, 1) < "\" Then
Path = Path & "\"
End If

' 'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(Path & "*.xls")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If

' On Error GoTo CleanUp

Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False

Set basebook = ThisWorkbook

'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath < ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop
total = Fnum

If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(Path & MyFiles(Fnum), 0, True)

Application.StatusBar = "Now processing File " & Fnum & "
of " & total

' Isolates the store number from the workbook name
stonum = mybook.Sheets("Home").Range("c3").Value
stonum = Format(stonum, "000")

For Each ws In mybook.Worksheets
ws.Activate
If ws.Name < "Home" Then

Sh = ws.Name

Set sourceRange = ws.Range("m7:m100")

Set myC = basebook.Sh.Range("m5:ba5").Find(stonum,
LookIn:=xlValues, LookAt:=xlWhole)

If Not myC Is Nothing Then
Tcol = myC.Column
Else
MsgBox stonum & " wasn't found"
GoTo CleanUp
End If

Trange = Cells(8, Tcol).Resize(93, 1).Address

Set destrange = basebook.ws.Range(Trange)

sourceRange.Copy
destrange.PasteSpecial xlPasteAll
Next ws

mybook.Close savechanges:=False

Next Fnum
End If

Application.StatusBar = False

MsgBox "Store FCs are Updated!"

CleanUp:
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.StatusBar = False

End Sub

'Basebook' is a summary workbook, designed to collect data from approx
30 external workbooks -- these external WBs are identical in setup,
including sheet names.

The code opens up each of the external workbooks and copies the
specified range from SheetA in mybook to SheetA (remember, sheet names
are identical) in Basebook .... using StoNum to identify the proper
column to paste the data into.

The problem is that I keep getting 'Next without For' errors and I
don't see where the problem is -- I have them all matched up, I
think. can you help?

TIA,
Ray

 
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
Find Problem John Excel Programming 2 September 28th 06 09:58 AM
Find and Find Next problem Richard Hocking Excel Programming 2 September 13th 06 03:51 PM
Find Next problem Terry K Excel Programming 8 November 21st 05 05:17 PM
problem with FIND cjsmith22 Excel Worksheet Functions 3 November 17th 05 11:03 PM
Find problem alanthecat Excel Programming 7 July 5th 05 01:17 PM


All times are GMT +1. The time now is 11:48 AM.

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"