Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Select failed?

This simple macro hides certain columns, then it's supposed to select
cell B3, but it tells me the select methods failed.

Sub HideColTop2AC()
Dim rTopCell As Range
Dim lColTop As Long
Dim WkSht As Worksheet
For Each WkSht In ActiveWorkbook.Worksheets
If Not Right(WkSht.Name, 7) = "Records" Then

Set rTopCell = WkSht.Range("3:3").find("top",
LookIn:=xlValues, LookAt:=xlPart)
If Not rTopCell Is Nothing Then
lColTop = rTopCell.Column

WkSht.Range(WkSht.Columns(lColTop),
WkSht.Columns("AC")).Hidden = True
WkSht.Range("B3").Select<---ERROR

End If
End If
Next
End Sub

Why is the select failing?
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Select failed?

The worksheet needs to be active

Sub HideColTop2AC()
Dim rTopCell As Range
Dim lColTop As Long
Dim WkSht As Worksheet
For Each WkSht In ActiveWorkbook.Worksheets
If Not Right(WkSht.Name, 7) = "Records" Then

Set rTopCell = WkSht.Range("3:3").Find("top", LookIn:=xlValues,
LookAt:=xlPart)
If Not rTopCell Is Nothing Then
lColTop = rTopCell.Column

WkSht.Range(WkSht.Columns(lColTop),
WkSht.Columns("AC")).Hidden = True
WkSht.Activate
WkSht.Range("B3").Select

End If
End If
Next
End Sub

--

HTH

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


"davegb" wrote in message
ups.com...
This simple macro hides certain columns, then it's supposed to select
cell B3, but it tells me the select methods failed.

Sub HideColTop2AC()
Dim rTopCell As Range
Dim lColTop As Long
Dim WkSht As Worksheet
For Each WkSht In ActiveWorkbook.Worksheets
If Not Right(WkSht.Name, 7) = "Records" Then

Set rTopCell = WkSht.Range("3:3").find("top",
LookIn:=xlValues, LookAt:=xlPart)
If Not rTopCell Is Nothing Then
lColTop = rTopCell.Column

WkSht.Range(WkSht.Columns(lColTop),
WkSht.Columns("AC")).Hidden = True
WkSht.Range("B3").Select<---ERROR

End If
End If
Next
End Sub

Why is the select failing?
Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Select failed?

Hi

The sheet is not active on that moment (can't select a cell in a sheet that is not active)
WkSht = is the sheet in the loop and that is not the activesheet

You can add a
WkSht.Select
line in the loop


--
Regards Ron de Bruin
http://www.rondebruin.nl


"davegb" wrote in message ups.com...
This simple macro hides certain columns, then it's supposed to select
cell B3, but it tells me the select methods failed.

Sub HideColTop2AC()
Dim rTopCell As Range
Dim lColTop As Long
Dim WkSht As Worksheet
For Each WkSht In ActiveWorkbook.Worksheets
If Not Right(WkSht.Name, 7) = "Records" Then

Set rTopCell = WkSht.Range("3:3").find("top",
LookIn:=xlValues, LookAt:=xlPart)
If Not rTopCell Is Nothing Then
lColTop = rTopCell.Column

WkSht.Range(WkSht.Columns(lColTop),
WkSht.Columns("AC")).Hidden = True
WkSht.Range("B3").Select<---ERROR

End If
End If
Next
End Sub

Why is the select failing?
Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Select failed?

Try using "WkSht.Range("B3").Activate" instead.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select failed?

The real answer is to remove that line unless you absolutely need B3 to be
selected. The code as written does not do any selecting except for that.

--
Regards,
Tom Ogilvy

"davegb" wrote in message
ups.com...
This simple macro hides certain columns, then it's supposed to select
cell B3, but it tells me the select methods failed.

Sub HideColTop2AC()
Dim rTopCell As Range
Dim lColTop As Long
Dim WkSht As Worksheet
For Each WkSht In ActiveWorkbook.Worksheets
If Not Right(WkSht.Name, 7) = "Records" Then

Set rTopCell = WkSht.Range("3:3").find("top",
LookIn:=xlValues, LookAt:=xlPart)
If Not rTopCell Is Nothing Then
lColTop = rTopCell.Column

WkSht.Range(WkSht.Columns(lColTop),
WkSht.Columns("AC")).Hidden = True
WkSht.Range("B3").Select<---ERROR

End If
End If
Next
End Sub

Why is the select failing?
Thanks





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Select failed?

Thanks for pointing that out, Tom! Turns out, I didn't need it. But I
learned something from it, so it was worth finding out.

Tom Ogilvy wrote:
The real answer is to remove that line unless you absolutely need B3 to be
selected. The code as written does not do any selecting except for that.

--
Regards,
Tom Ogilvy

"davegb" wrote in message
ups.com...
This simple macro hides certain columns, then it's supposed to select
cell B3, but it tells me the select methods failed.

Sub HideColTop2AC()
Dim rTopCell As Range
Dim lColTop As Long
Dim WkSht As Worksheet
For Each WkSht In ActiveWorkbook.Worksheets
If Not Right(WkSht.Name, 7) = "Records" Then

Set rTopCell = WkSht.Range("3:3").find("top",
LookIn:=xlValues, LookAt:=xlPart)
If Not rTopCell Is Nothing Then
lColTop = rTopCell.Column

WkSht.Range(WkSht.Columns(lColTop),
WkSht.Columns("AC")).Hidden = True
WkSht.Range("B3").Select<---ERROR

End If
End If
Next
End Sub

Why is the select failing?
Thanks


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
Error: method 'select' of object_worksheet' failed Carl Excel Discussion (Misc queries) 4 September 9th 06 08:52 PM
What did I do? (Select Method of Range Class Failed ) HotRod Excel Programming 9 May 20th 05 02:11 PM
Select method of Range class failed - but why??? Orion[_2_] Excel Programming 3 December 21st 04 03:28 PM
select method of range class failed Joseph[_40_] Excel Programming 0 September 28th 04 04:08 PM
select method of range class failed Joseph[_38_] Excel Programming 1 September 28th 04 03:21 PM


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