Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel Looping code....


I previously posted and was able to get the code help I needed to open
all workbooks in a specified folder....Now I've added some code to copy
the worksheets to a new workbook...which it does fine, but it keeps
looping...

Basically, I can't get it to stop after it works thru the 5 open
workbooks and copies the sheets i've specified to the new workbook. As
w/ the original code, the wbks it copies from range from 4 - 20
daily...I've posted the original working code, and then the code w/
updated commands, that causing me grief...


Dim x As Integer
Dim WB As String
Dim wbk As Workbook

For x = 1 To 100

WB = "G:\ClaimsXten\TEST\RBA\RBA " & x & ".xls"

On Error Resume Next

Set wbk = Workbooks.Open(Filename:=WB)
Worksheets("Current Rules - 1").Activate
On Error GoTo 0
If Not wbk Is Nothing Then

End If
Next

End Sub
THIS WORKS GREAT...BELOW IS WHERE I'VE MESSED IT UP
+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_ +_+_+_+_+_


Dim x As Integer
Dim WB As String
Dim wbk As Workbook


For x = 1 To 100


WB = "G:\ClaimsXten\TEST\RBA\RBA " & x & ".xls"

On Error Resume Next

Set wbk = Workbooks.Open(Filename:=WB)
Worksheets("Current Rules - 1").Activate

On Error GoTo 0

If Not wbk Is Nothing Then
'NEW CODING CAUSING LOOP
Columns("A:BB").Select
With Selection
..HorizontalAlignment = xlCenter
..VerticalAlignment = xlBottom
..WrapText = False
..Orientation = 0
..AddIndent = False
..IndentLevel = 0
..ShrinkToFit = False
..ReadingOrder = xlContext
..MergeCells = False
End With

Sheets("Current Rules - 1").Select
Sheets("Current Rules - 1").Select
Sheets("Current Rules - 1").Copy Befo=Workbooks("RBA
Indi.xls").Sheets(1)
Application.Run "PERSONAL.XLS!rbaHideandFilter"
'Code End

End If
Next




End Sub


--
have_a_cup
------------------------------------------------------------------------
have_a_cup's Profile: http://www.excelforum.com/member.php...o&userid=35394
View this thread: http://www.excelforum.com/showthread...hreadid=552945

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Excel Looping code....

a VERY cursory look suggests

For x = 1 To 100
For x = 1 To workbooks.count


--
Don Guillett
SalesAid Software

"have_a_cup" wrote
in message ...

I previously posted and was able to get the code help I needed to open
all workbooks in a specified folder....Now I've added some code to copy
the worksheets to a new workbook...which it does fine, but it keeps
looping...

Basically, I can't get it to stop after it works thru the 5 open
workbooks and copies the sheets i've specified to the new workbook. As
w/ the original code, the wbks it copies from range from 4 - 20
daily...I've posted the original working code, and then the code w/
updated commands, that causing me grief...


Dim x As Integer
Dim WB As String
Dim wbk As Workbook

For x = 1 To 100

WB = "G:\ClaimsXten\TEST\RBA\RBA " & x & ".xls"

On Error Resume Next

Set wbk = Workbooks.Open(Filename:=WB)
Worksheets("Current Rules - 1").Activate
On Error GoTo 0
If Not wbk Is Nothing Then

End If
Next

End Sub
THIS WORKS GREAT...BELOW IS WHERE I'VE MESSED IT UP
+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_ +_+_+_+_+_


Dim x As Integer
Dim WB As String
Dim wbk As Workbook


For x = 1 To 100


WB = "G:\ClaimsXten\TEST\RBA\RBA " & x & ".xls"

On Error Resume Next

Set wbk = Workbooks.Open(Filename:=WB)
Worksheets("Current Rules - 1").Activate

On Error GoTo 0

If Not wbk Is Nothing Then
'NEW CODING CAUSING LOOP
Columns("A:BB").Select
With Selection
HorizontalAlignment = xlCenter
VerticalAlignment = xlBottom
WrapText = False
Orientation = 0
AddIndent = False
IndentLevel = 0
ShrinkToFit = False
ReadingOrder = xlContext
MergeCells = False
End With

Sheets("Current Rules - 1").Select
Sheets("Current Rules - 1").Select
Sheets("Current Rules - 1").Copy Befo=Workbooks("RBA
Indi.xls").Sheets(1)
Application.Run "PERSONAL.XLS!rbaHideandFilter"
'Code End

End If
Next




End Sub


--
have_a_cup
------------------------------------------------------------------------
have_a_cup's Profile:
http://www.excelforum.com/member.php...o&userid=35394
View this thread: http://www.excelforum.com/showthread...hreadid=552945



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel Looping code....



Dim x As Integer
Dim WB As String
Dim wbk As Workbook


For x = 1 To 100


WB = "G:\ClaimsXten\TEST\RBA\RBA " & x & ".xls"

On Error Resume Next
Set wbk = Nothing
Set wbk = Workbooks.Open(Filename:=WB)
if wbk is nothing then exit sub
Worksheets("Current Rules - 1").Activate

On Error GoTo 0


With Columns("A:BB")

.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Sheets("Current Rules - 1").Select
Sheets("Current Rules - 1").Copy _
Befo=Workbooks("RBAIndi.xls").Sheets(1)
Application.Run "PERSONAL.XLS!rbaHideandFilter"
wbk.Close SaveChanges:=False
Next

--
Regards,
Tom Ogilvy


"have_a_cup" wrote
in message ...

I previously posted and was able to get the code help I needed to open
all workbooks in a specified folder....Now I've added some code to copy
the worksheets to a new workbook...which it does fine, but it keeps
looping...

Basically, I can't get it to stop after it works thru the 5 open
workbooks and copies the sheets i've specified to the new workbook. As
w/ the original code, the wbks it copies from range from 4 - 20
daily...I've posted the original working code, and then the code w/
updated commands, that causing me grief...


Dim x As Integer
Dim WB As String
Dim wbk As Workbook

For x = 1 To 100

WB = "G:\ClaimsXten\TEST\RBA\RBA " & x & ".xls"

On Error Resume Next

Set wbk = Workbooks.Open(Filename:=WB)
Worksheets("Current Rules - 1").Activate
On Error GoTo 0
If Not wbk Is Nothing Then

End If
Next

End Sub
THIS WORKS GREAT...BELOW IS WHERE I'VE MESSED IT UP
+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_ +_+_+_+_+_


Dim x As Integer
Dim WB As String
Dim wbk As Workbook


For x = 1 To 100


WB = "G:\ClaimsXten\TEST\RBA\RBA " & x & ".xls"

On Error Resume Next

Set wbk = Workbooks.Open(Filename:=WB)
Worksheets("Current Rules - 1").Activate

On Error GoTo 0

If Not wbk Is Nothing Then
'NEW CODING CAUSING LOOP
Columns("A:BB").Select
With Selection
HorizontalAlignment = xlCenter
VerticalAlignment = xlBottom
WrapText = False
Orientation = 0
AddIndent = False
IndentLevel = 0
ShrinkToFit = False
ReadingOrder = xlContext
MergeCells = False
End With

Sheets("Current Rules - 1").Select
Sheets("Current Rules - 1").Select
Sheets("Current Rules - 1").Copy Befo=Workbooks("RBA
Indi.xls").Sheets(1)
Application.Run "PERSONAL.XLS!rbaHideandFilter"
'Code End

End If
Next




End Sub


--
have_a_cup
------------------------------------------------------------------------
have_a_cup's Profile:

http://www.excelforum.com/member.php...o&userid=35394
View this thread: http://www.excelforum.com/showthread...hreadid=552945



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
Help with Looping Code JimMay Excel Programming 5 June 6th 06 03:43 AM
stopping code from looping tjb Excel Worksheet Functions 3 December 7th 05 02:02 AM
Looping macros using VB code accessuser1308 Excel Discussion (Misc queries) 2 March 9th 05 11:11 PM
Looping code in Excel macro Robert Excel Programming 2 February 25th 05 04:33 AM
Code looping when it should not Todd Huttenstine Excel Programming 3 May 13th 04 09:37 PM


All times are GMT +1. The time now is 11:52 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"