Thread: select range...
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default select range...

Not your fault. This is a common error.
--
Gary''s Student - gsnu200769


"Hemant_india" wrote:

thanks
must get it in my head
sort of out of touch i guess
--
hemu


"Gary''s Student" wrote:

Make sure that worksheets(1) has been activated before trying to Select a
range on that worksheet. This code:

Sub ThisCanFail()
Dim r As Range
Set r = Worksheets(1).UsedRange
MsgBox (r.Address)
r.Select
End Sub

will definitely generate an error if it is run with a different worksheet
being active.
--
Gary''s Student - gsnu200769


"Hemant_india" wrote:

hi guys
what's wrong with the following coe?
i am all gone mad

Dim rnghead As Range
Dim head1()
Set rnghead = Worksheets(1).UsedRange
ReDim head1(1 To rnghead.Columns.Count)
For n = 1 To rnghead.Columns.Count
head1(n) = rnghead.Cells(1, n)
Next n
With ActiveSheet
For n = 1 To rnghead.Columns.Count
'rnghead.Cells(1, n).Select ''error select range method fails'

rnghead.Cells(1, n).Interior.ColorIndex = 10
next
end with

please ...
--
hemu