ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   select range... (https://www.excelbanter.com/excel-programming/406180-select-range.html)

Hemant_india[_2_]

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

Gary''s Student

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


Hemant_india[_2_]

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


Gary''s Student

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



All times are GMT +1. The time now is 03:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com