View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban[_2_] Alan Beban[_2_] is offline
external usenet poster
 
Posts: 783
Default Range type variable oddness

Here's a way to avoid the lack of qualification problem referred to by
Tom Ogilvy and Chip Pearson:

Dim TempData As Worksheet
Dim rng As Range, SearchRange As Range
Set TempData = Sheets("Sheet3")
Set rng = TempData.Range("A1")
Set SearchRange = TempData.Range(rng(1, 1), rng(1, 26))

Alan Beban

Nick wrote:
I wish to do this:

Dim TempData As Worksheet
Dim SearchRange As Range

Set TempData = ThisWorkbook.Worksheets("Temp Data")

Set SearchRange = TempData.Range(Cells(1, 1), Cells(1, 26))

The code currently comes up with an error message saying
the range method has failed.

I do need to declare tempdata and searchrange separately
cos I will be changing the searchrange in a "for, next"
loop.

I always thought that range was a property of worksheets
not a method. Bit confused and although I have tried many
different variations I can't get one to work.

Any reponse would be, as always, much appreciated.

Nick Shinkins