select range...

  • Thread starter Thread starter Hemant_india
  • Start date Start date
H

Hemant_india

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 ...
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top