#1   Report Post  
Greg B
 
Posts: n/a
Default Help with code

What I am trying to do is have a macro lookup cell b1 from sheets21 to
sheet120 and when it finds the first sheet that this cell is blank to
execute a macro.

I used to use the code below but it is way to long over this many sheets.

If Sheet21.Range("AV3") = "" Then
Sheet21.Select
Else
If Sheet22.Range("AV3") = "" Then
Sheet22.Select
Else
If Sheet23.Range("AV3") = "" Then
Sheet23.Select
Else


etc.

Thanks Greg


  #2   Report Post  
Art
 
Posts: n/a
Default Help with code

Greg,

You can do the following, although it has a problem that I'll describe:

dim s as worksheet
for each s in worksheets
if s.range("AV3")="" then
s.select
endif
next s

Now the problem is that this goes through ALL sheets, not just Sheet21
through Sheet120. There are a couple of adjustments you can make.

First, if you can rename your sheets so that you have Sheet021 instead of
Sheet21, then you can use an if statement to find out if the final sheet is
in that range.

If you can't rename them, you could put them into an array and loop through
the array. Or, you could write some code to parse the name and determine if
it's a valid sheet name.

I hope this is of some help.

Art

"Greg B" wrote:

What I am trying to do is have a macro lookup cell b1 from sheets21 to
sheet120 and when it finds the first sheet that this cell is blank to
execute a macro.

I used to use the code below but it is way to long over this many sheets.

If Sheet21.Range("AV3") = "" Then
Sheet21.Select
Else
If Sheet22.Range("AV3") = "" Then
Sheet22.Select
Else
If Sheet23.Range("AV3") = "" Then
Sheet23.Select
Else


etc.

Thanks Greg



  #3   Report Post  
Bob Phillips
 
Posts: n/a
Default Help with code

For Each sh In Activeworkbook.Worksheets
tmp = CLng(Right(sh.Name(Len(sh.Name)-5))
If tmp = 21 And tmp <= 120 Then
If sh.Range("AV3").Value = "" Then
sh.Select
Exit For
End If
End If
Next sh

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Greg B" wrote in message
...
What I am trying to do is have a macro lookup cell b1 from sheets21 to
sheet120 and when it finds the first sheet that this cell is blank to
execute a macro.

I used to use the code below but it is way to long over this many sheets.

If Sheet21.Range("AV3") = "" Then
Sheet21.Select
Else
If Sheet22.Range("AV3") = "" Then
Sheet22.Select
Else
If Sheet23.Range("AV3") = "" Then
Sheet23.Select
Else


etc.

Thanks Greg




  #4   Report Post  
Greg B
 
Posts: n/a
Default Help with code

Thanks Bob
"Bob Phillips" wrote in message
...
For Each sh In Activeworkbook.Worksheets
tmp = CLng(Right(sh.Name(Len(sh.Name)-5))
If tmp = 21 And tmp <= 120 Then
If sh.Range("AV3").Value = "" Then
sh.Select
Exit For
End If
End If
Next sh

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Greg B" wrote in message
...
What I am trying to do is have a macro lookup cell b1 from sheets21 to
sheet120 and when it finds the first sheet that this cell is blank to
execute a macro.

I used to use the code below but it is way to long over this many sheets.

If Sheet21.Range("AV3") = "" Then
Sheet21.Select
Else
If Sheet22.Range("AV3") = "" Then
Sheet22.Select
Else
If Sheet23.Range("AV3") = "" Then
Sheet23.Select
Else


etc.

Thanks Greg






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
Change case...help please Terry Excel Worksheet Functions 14 October 2nd 05 12:29 PM
Macro for changing text to Proper Case JPriest Excel Worksheet Functions 3 August 8th 05 09:31 PM
Using other workbooks.. DavidMunday Excel Worksheet Functions 2 July 1st 05 07:35 AM
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 4th 05 10:50 AM


All times are GMT +1. The time now is 07:18 AM.

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"