Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Go To Next Worksheet in Loop

Hi-

I have the following code. When it runs I get a "Subscript out of
range" error. Can anyone clean this up for me and get me to the next
sheet in the workbook? Thanks in advance for your help!

For x = ActiveSheet.Index + 1 To Worksheets(Worksheets.Count).Index
Range("B2").Select
If ActiveCell.Value = "Distributor:" Then
FUNCTION1
End If
Sheets(x).Select
Next x

Thanks,
Chris

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Go To Next Worksheet in Loop

Thanks for the reply Don.

This code does not move to the next sheet....

-Chris

Don Guillett wrote:
No need to select

For i = ActiveSheet.Index To Worksheets.Count
If UCase(Range("B2")) = "DISTRIBUTOR:" Then FUNCTION1
Next i


--
Don Guillett
SalesAid Software

wrote in message
ups.com...
Hi-

I have the following code. When it runs I get a "Subscript out of
range" error. Can anyone clean this up for me and get me to the next
sheet in the workbook? Thanks in advance for your help!

For x = ActiveSheet.Index + 1 To Worksheets(Worksheets.Count).Index
Range("B2").Select
If ActiveCell.Value = "Distributor:" Then
FUNCTION1
End If
Sheets(x).Select
Next x

Thanks,
Chris


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Go To Next Worksheet in Loop

Hi Don-

Now when I run the macro it disregards the value in "B2" and just runs
the function on all sheets. The value in B2 has to be "Distributor:"
in order for the function to run.

Sorry for being a pain! You are helping me tremendously and I
appreciate the effort!

Thanks Again,
Chris

Don Guillett wrote:
OOOOOOOh MY bad!!

For i = ActiveSheet.Index To Worksheets.Count
If UCase(sheets(i).Range("B2")) = "DISTRIBUTOR:" Then FUNCTION1
Next i


--
Don Guillett
SalesAid Software

"Don Guillett" wrote in message
...
That is correct and by design. That is because you rarely have to select
to do what you want. Why waste time and effort doing that?

--
Don Guillett
SalesAid Software

wrote in message
ups.com...
Thanks for the reply Don.

This code does not move to the next sheet....

-Chris

Don Guillett wrote:
No need to select

For i = ActiveSheet.Index To Worksheets.Count
If UCase(Range("B2")) = "DISTRIBUTOR:" Then FUNCTION1
Next i


--
Don Guillett
SalesAid Software

wrote in message
ups.com...
Hi-

I have the following code. When it runs I get a "Subscript out of
range" error. Can anyone clean this up for me and get me to the next
sheet in the workbook? Thanks in advance for your help!

For x = ActiveSheet.Index + 1 To Worksheets(Worksheets.Count).Index
Range("B2").Select
If ActiveCell.Value = "Distributor:" Then
FUNCTION1
End If
Sheets(x).Select
Next x

Thanks,
Chris





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
Worksheet loop won't loop L. Howard Kittle Excel Programming 4 March 17th 06 12:56 AM
Do loop to add a new worksheet Alex Excel Programming 2 August 19th 04 11:35 PM
how do you loop through each worksheet? dundonald Excel Programming 16 January 11th 04 02:20 PM
worksheet loop scott[_8_] Excel Programming 8 November 17th 03 09:49 PM
How? Macro to copy range to new worksheet, name new worksheet, loop Repoman Excel Programming 9 October 9th 03 01:45 PM


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