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

Can anyone help with this Ver 8.0 Excel problem?

When running this code it fails at the Select line even though "Bingo" is a
valid Worksheet in the Workbook :-

Dim sht As WorkSheet

Set sht = Worksheets("Bingo")
With sht
.Range(Cells(1, 2), Cells(1, 2)).Select
End With

Does it need ActiveWorkbook in front of Worksheets?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Range selection

Try this:

Set sht = Sheets("Bingo")
With sht
.Range(Cells(1, 2), Cells(1, 2)).Select
End With

"Andy" wrote in message
...
Can anyone help with this Ver 8.0 Excel problem?

When running this code it fails at the Select line even though "Bingo" is
a
valid Worksheet in the Workbook :-

Dim sht As WorkSheet

Set sht = Worksheets("Bingo")
With sht
.Range(Cells(1, 2), Cells(1, 2)).Select
End With

Does it need ActiveWorkbook in front of Worksheets?

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Range selection

Ok.

That was stupid of me.

What range are you trying to select? Is it B1? Is there supposed to be
some sort of range of cells? The 'Cells portions are the same. But I'm not
sure what you're trying to do with that statement. Please elaborate.

Regards.
Paul

"PCLIVE" wrote in message
...
Try this:

Set sht = Sheets("Bingo")
With sht
.Range(Cells(1, 2), Cells(1, 2)).Select
End With

"Andy" wrote in message
...
Can anyone help with this Ver 8.0 Excel problem?

When running this code it fails at the Select line even though "Bingo" is
a
valid Worksheet in the Workbook :-

Dim sht As WorkSheet

Set sht = Worksheets("Bingo")
With sht
.Range(Cells(1, 2), Cells(1, 2)).Select
End With

Does it need ActiveWorkbook in front of Worksheets?

Thanks.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Range selection

First, you can only select a range on the active sheet.

Second, those cells() references are unqualified. If your code is in a General
module, then they'll refer to the activesheet--which may not be Bingo.

I'd do:

Dim sht As WorkSheet
Set sht = Worksheets("Bingo")
With sht
.select
.Range(.Cells(1, 2), .Cells(1, 2)).Select
End With

notice the dots in front of cells(). That means that they refer to the object
in the previous With statement--in this case sht (aka worksheets("Bingo")).




Andy wrote:

Can anyone help with this Ver 8.0 Excel problem?

When running this code it fails at the Select line even though "Bingo" is a
valid Worksheet in the Workbook :-

Dim sht As WorkSheet

Set sht = Worksheets("Bingo")
With sht
.Range(Cells(1, 2), Cells(1, 2)).Select
End With

Does it need ActiveWorkbook in front of Worksheets?

Thanks.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Range selection

Thanks Paul/Dave - I think that will solve it - I'll test tomorrow. The key
as you say is to declare the sheet active. Paul - the range is indeed 1 cell
but I will change this to a proper range once the general syntax is fixed.

Cheers,
Andy.

"Dave Peterson" wrote:

First, you can only select a range on the active sheet.

Second, those cells() references are unqualified. If your code is in a General
module, then they'll refer to the activesheet--which may not be Bingo.

I'd do:

Dim sht As WorkSheet
Set sht = Worksheets("Bingo")
With sht
.select
.Range(.Cells(1, 2), .Cells(1, 2)).Select
End With

notice the dots in front of cells(). That means that they refer to the object
in the previous With statement--in this case sht (aka worksheets("Bingo")).




Andy wrote:

Can anyone help with this Ver 8.0 Excel problem?

When running this code it fails at the Select line even though "Bingo" is a
valid Worksheet in the Workbook :-

Dim sht As WorkSheet

Set sht = Worksheets("Bingo")
With sht
.Range(Cells(1, 2), Cells(1, 2)).Select
End With

Does it need ActiveWorkbook in front of Worksheets?

Thanks.


--

Dave Peterson



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
Narrow Range based on Selection in Another Range David Excel Discussion (Misc queries) 3 July 1st 07 05:12 PM
Identifying a selection of a selection of a range swimfast Excel Worksheet Functions 1 March 1st 07 02:51 AM
Excel VBA - Range(Selection, Selection.End(xlDown)).Name issue. jonH Excel Programming 3 June 7th 04 09:13 PM
Creating range name for a range selection Mervyn Thomas Excel Programming 1 January 26th 04 05:18 PM
Selection of range me[_4_] Excel Programming 1 September 10th 03 05:05 PM


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