Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
sgl sgl is offline
external usenet poster
 
Posts: 80
Default Determine specific range

Hi all,

I have the following code

Dim MyBook as Workbook
Dim SrcRange as Range
Dim ShtName as Variant
Dim N as Interger

.... Code ...

set
SrcRange=Mybook.Workshhets(ShtName(N)).Range(Range ("A2"),Range("A2").SpecialCells(xlLastCell))

.... morwe code

This gives me an Application or Object Defined Error. If I use the following
it works well but I do not get the specific range I need.

set SrcRange=Mybook.Workshhets(ShtName(N)).UsedRange

Can someone pleasse help with this as it is driving me barmy

Thanx in Advance/sgl


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Determine specific range


SrcRange=Mybook.Workshhets(ShtName(N)).Range(Range ("A2"),Range("A2").SpecialCells(xlLastCell))
Hi,
have you tried to make this ?

SrcRange =
MyBook.WorkSheets(ShtName(N)).Range("A2).Specialce lls(xlastcell)

Hope this will help you

  #3   Report Post  
Posted to microsoft.public.excel.programming
sgl sgl is offline
external usenet poster
 
Posts: 80
Default Determine specific range

Sorry this doesn't work It only selects the last cell in the range whereas I
need to select the whole range "Block"

"VoTiger" wrote:


SrcRange=Mybook.Workshhets(ShtName(N)).Range(Range ("A2"),Range("A2").SpecialCells(xlLastCell))
Hi,
have you tried to make this ?

SrcRange =
MyBook.WorkSheets(ShtName(N)).Range("A2).Specialce lls(xlastcell)

Hope this will help you


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Determine specific range

Set SrcRange = Mybook.Worksheets(ShtName(N)).Range(Range("A2"),
Range("A2").SpecialCells(xlLastCell))


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"sgl" wrote in message
...
Hi all,

I have the following code

Dim MyBook as Workbook
Dim SrcRange as Range
Dim ShtName as Variant
Dim N as Interger

... Code ...

set

SrcRange=Mybook.Workshhets(ShtName(N)).Range(Range ("A2"),Range("A2").Special
Cells(xlLastCell))

... morwe code

This gives me an Application or Object Defined Error. If I use the

following
it works well but I do not get the specific range I need.

set SrcRange=Mybook.Workshhets(ShtName(N)).UsedRange

Can someone pleasse help with this as it is driving me barmy

Thanx in Advance/sgl




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Determine specific range

The range("a2") references are unqualified. So they belong to the
activesheet--which may not be mybook.worksheets(shtname(n)) (watch your spelling
of worksheets, too!)

I'd use:

with mybook.worksheets(shtname(n))
Set SrcRange = .Range(.Range("a2"), _
.Range("a2").SpecialCells(xlCellTypeLastCell))
end with

or

with mybook.worksheets(shtname(n))
Set SrcRange = .Range("A2", .cells.SpecialCells(xlCellTypeLastCell))
end with

sgl wrote:

Hi all,

I have the following code

Dim MyBook as Workbook
Dim SrcRange as Range
Dim ShtName as Variant
Dim N as Interger

... Code ...

set
SrcRange=Mybook.Workshhets(ShtName(N)).Range(Range ("A2"),Range("A2").SpecialCells(xlLastCell))

... morwe code

This gives me an Application or Object Defined Error. If I use the following
it works well but I do not get the specific range I need.

set SrcRange=Mybook.Workshhets(ShtName(N)).UsedRange

Can someone pleasse help with this as it is driving me barmy

Thanx in Advance/sgl


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
sgl sgl is offline
external usenet poster
 
Posts: 80
Default Determine specific range

Thank you all for your assistance. I realised my mistake after posting. I
have used a slightly different coding which seems to work

with mybook.worksheets(shtname(n))
Set SrcRange = .Range("a2", .Range("a2").SpecialCells(xlLastCell))
end with

thanx again/sgl

"Dave Peterson" wrote:

The range("a2") references are unqualified. So they belong to the
activesheet--which may not be mybook.worksheets(shtname(n)) (watch your spelling
of worksheets, too!)

I'd use:

with mybook.worksheets(shtname(n))
Set SrcRange = .Range(.Range("a2"), _
.Range("a2").SpecialCells(xlCellTypeLastCell))
end with

or

with mybook.worksheets(shtname(n))
Set SrcRange = .Range("A2", .cells.SpecialCells(xlCellTypeLastCell))
end with

sgl wrote:

Hi all,

I have the following code

Dim MyBook as Workbook
Dim SrcRange as Range
Dim ShtName as Variant
Dim N as Interger

... Code ...

set
SrcRange=Mybook.Workshhets(ShtName(N)).Range(Range ("A2"),Range("A2").SpecialCells(xlLastCell))

... morwe code

This gives me an Application or Object Defined Error. If I use the following
it works well but I do not get the specific range I need.

set SrcRange=Mybook.Workshhets(ShtName(N)).UsedRange

Can someone pleasse help with this as it is driving me barmy

Thanx in Advance/sgl


--

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
How to determine the value within specific cell position? Eric Excel Discussion (Misc queries) 5 April 9th 10 01:15 PM
How to determine whether a list contains a specific value? Eric Excel Discussion (Misc queries) 4 June 29th 07 12:50 AM
determine the active workbook containing a specific sheet Valeria Excel Programming 1 September 29th 05 08:21 PM
Determine which cells from a specific range equal a certain sum Maxter21 Excel Worksheet Functions 1 July 20th 05 09:44 PM
Determine shape name associated with a specific cell [email protected] Excel Discussion (Misc queries) 1 May 12th 05 12:49 AM


All times are GMT +1. The time now is 11:55 PM.

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"