Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How to specify a range?

In this line of code I want to analyse each cell in the range including A2
to the last non-blank cell in column A:

For Each rcd In Worksheets("Data").Range("A2", Selection.End(xlDown))

How do I specify this range without selecting anything?

I've tried (apart from what's above) .Range("A2", Range("A:A").End(xlDown))
which also doesn't work

Any help greatly appreciated

cheers,

Damien
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How to specify a range?

Damien McBain wrote:

In this line of code I want to analyse each cell in the range including A2
to the last non-blank cell in column A:

For Each rcd In Worksheets("Data").Range("A2", Selection.End(xlDown))

How do I specify this range without selecting anything?

I've tried (apart from what's above) .Range("A2", Range("A:A").End(xlDown))
which also doesn't work


Here's the whole thing:

Sub ProcessData()
=================================
For Each rt In Worksheets("Data").Range("A2", Range("A2").End(xlDown))

With Worksheets.Add
.Name = rt
End With
For Each rcd In Worksheets("Data").Range("A2", _
Range("A2").End(xlDown))
If rcd.Value = rt.Value Then
rcd.EntireRow.Copy
Worksheets(rt).Range("A2", Selection.End(xlDown) + 1).Paste
Else
End If
Next rcd

Next rt
End Sub
=================================

It runs fine up till the line after the first "End With". Is the problem my
range selection statement or the way I'm nesting the For...Next?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default How to specify a range?

Voila

For Each rcd In Worksheets("Data").Range("A2",
Worksheets("Data").Range("A2").End(xlDown))
Regards
JY

"Damien McBain" wrote in message
...
In this line of code I want to analyse each cell in the range including A2
to the last non-blank cell in column A:

For Each rcd In Worksheets("Data").Range("A2", Selection.End(xlDown))

How do I specify this range without selecting anything?

I've tried (apart from what's above) .Range("A2",
Range("A:A").End(xlDown))
which also doesn't work

Any help greatly appreciated

cheers,

Damien



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default How to specify a range?

In : For Each rt In Worksheets("Data").Range("A2", Range("A2").End(xlDown))
Worksheets("Data").Range("A2" : Refer to A2 on Worksheets("Data")
Range("A2").End(xlDown) Refer to all cell in column A on the active sheet,.
ie new wk RT

Therfor you have to repeat the sheet name : Worksheets("Data").Range("A2",
Worksheets("Data").Range("A2").End(xlDown))
Regards
JY


"Damien McBain" wrote in message
...
Damien McBain wrote:

In this line of code I want to analyse each cell in the range including
A2
to the last non-blank cell in column A:

For Each rcd In Worksheets("Data").Range("A2", Selection.End(xlDown))

How do I specify this range without selecting anything?

I've tried (apart from what's above) .Range("A2",
Range("A:A").End(xlDown))
which also doesn't work


Here's the whole thing:

Sub ProcessData()
=================================
For Each rt In Worksheets("Data").Range("A2", Range("A2").End(xlDown))

With Worksheets.Add
.Name = rt
End With
For Each rcd In Worksheets("Data").Range("A2", _
Range("A2").End(xlDown))
If rcd.Value = rt.Value Then
rcd.EntireRow.Copy
Worksheets(rt).Range("A2", Selection.End(xlDown) + 1).Paste
Else
End If
Next rcd

Next rt
End Sub
=================================

It runs fine up till the line after the first "End With". Is the problem
my
range selection statement or the way I'm nesting the For...Next?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How to specify a range?

Jean-Yves wrote:

In : For Each rt In Worksheets("Data").Range("A2", Range("A2").End(xlDown))
Worksheets("Data").Range("A2" : Refer to A2 on Worksheets("Data")
Range("A2").End(xlDown) Refer to all cell in column A on the active sheet,.
ie new wk RT

Therfor you have to repeat the sheet name : Worksheets("Data").Range("A2",
Worksheets("Data").Range("A2").End(xlDown))
Regards
JY


Cheers JY, thanks to you that part of the code is working now. The bit I'm
having trouble with now is pasting into the new sheet. I need to paste into
the first empty cell in column A.

Would you mind filling in the blanks here?:

Worksheets(rt).<the first empty cell in column a.Paste

thanks again,

Damien


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default How to specify a range?

Voila,
Worksheets(rt).range("A2").End(xlDown).Offset(1,0)
Regards
JY

"Damien McBain" wrote in message
...
Jean-Yves wrote:

In : For Each rt In Worksheets("Data").Range("A2",
Range("A2").End(xlDown))
Worksheets("Data").Range("A2" : Refer to A2 on Worksheets("Data")
Range("A2").End(xlDown) Refer to all cell in column A on the active
sheet,.
ie new wk RT

Therfor you have to repeat the sheet name :
Worksheets("Data").Range("A2",
Worksheets("Data").Range("A2").End(xlDown))
Regards
JY


Cheers JY, thanks to you that part of the code is working now. The bit I'm
having trouble with now is pasting into the new sheet. I need to paste
into
the first empty cell in column A.

Would you mind filling in the blanks here?:

Worksheets(rt).<the first empty cell in column a.Paste

thanks again,

Damien



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 do I enter formula sum(range+range)*0.15 sumif(range=3) tkw Excel Discussion (Misc queries) 2 October 1st 09 09:17 PM
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
Range.Find returns cell outside of range when range set to single cell Frank Jones Excel Programming 12 June 10th 04 04:22 AM
how to? set my range= my UDF argument (range vs. value in range) [advanced?] Keith R[_3_] Excel Programming 2 August 11th 03 05:55 PM


All times are GMT +1. The time now is 11:23 AM.

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"