#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 40
Default Won't Compile

I am trying to come up with a VB routine IN XL2007 which hides all but a
specified sheet. In the test routine I have written the specified sheet is
the first sheet, but this is arbitrary. I would be most grateful if someone
could explain the error I get when I try to compile the following:

Sub Testsub()
Dim Sheet, Sheet_ As Worksheet, I As Integer
Set Sheet = ActiveWorkbook.Sheets(1)
MsgBox ActiveWorkbook.Sheets.Count
For I = 1 To ActiveWorkbook.Sheets.Count
Set Sheet_ = ActiveWorkbook.Sheets(I)
If Sheet_ < Sheet Then Sheet_.Hide
Next
Sheet.Activate
End Sub


--
-regards
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default Won't Compile

I got it to work, with some modifications:

Sub Testsub()
Dim Sheet, Sheet_ As Worksheet, I As Integer
Set Sheet = ActiveWorkbook.Sheets(1)
MsgBox ActiveWorkbook.Sheets.Count
For I = 1 To ActiveWorkbook.Sheets.Count
Set Sheet_ = ActiveWorkbook.Sheets(I)
If Sheet_.Name < Sheet.Name Then Sheet_.Visible = False
Next
Sheet.Activate
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Won't Compile

On Jul 30, 12:58 pm, GeorgeJ
wrote:
I am trying to come up with a VB routine IN XL2007 which hides all but a
specified sheet. In the test routine I have written the specified sheet is
the first sheet, but this is arbitrary. I would be most grateful if someone
could explain the error I get when I try to compile the following:

Sub Testsub()
Dim Sheet, Sheet_ As Worksheet, I As Integer
Set Sheet = ActiveWorkbook.Sheets(1)
MsgBox ActiveWorkbook.Sheets.Count
For I = 1 To ActiveWorkbook.Sheets.Count
Set Sheet_ = ActiveWorkbook.Sheets(I)
If Sheet_ < Sheet Then Sheet_.Hide
Next
Sheet.Activate
End Sub

--
-regards


Here are 2 examples, the first one, will hide all sheets exept the
active sheet, the second one will hide all sheets exept for the one U
pass as a parameter to the sub i.e you call: HideSheetsbyName "Sheet2"

Sub HideSheets()
For Each Sht In ActiveWorkbook.Sheets
If Sht.Name < ActiveSheet.Name Then
Sht.Visible = False
End If
Next Sht
End Sub

Sub HideSheetsbyName(S As String)
For Each Sht In ActiveWorkbook.Sheets
If Sht.Name < S Then
Sht.Visible = False
End If
Next Sht
End Sub

Rgd's

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 40
Default Won't Compile

I'd like to thank you both for your very helpful comments. I realize my
mistake was trying to do a comparison between objects rather than fields of
objects.

In the process of implementing RGD's HideSheets routine I discovered
something strange which may intrigue you. Usually, when you type the name of
a system object such as activeworkbook and then move the cursor to the next
line the VB editor instantly performs the capitalization, e. g. in this case
it turns

activeworkbook

into

ActiveWorkbook.

I notice that in the case of activesheet, just the opposite happens. E. G.
the VB editor turns

ActiveSheet

into

activesheet

But it does interpret activesheet correctly! This is curious, because in
the help file the object is presented as ActiveSheet.

Its not a big deal, but does anyone have any idea what's going on here? (I'm
using XL2007)
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
Compile Error. Else without If? PaulW Excel Discussion (Misc queries) 6 September 1st 06 03:38 PM
Compile Error on Chr(13) scottfoxall Excel Discussion (Misc queries) 3 August 22nd 06 12:34 PM
compile data mike1 Excel Discussion (Misc queries) 1 July 8th 06 02:44 AM
help help help compile error ashw1984 Excel Discussion (Misc queries) 1 January 30th 06 12:45 PM
compile errors johnny Excel Discussion (Misc queries) 1 February 24th 05 11:49 PM


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