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

Hi

My problem is similar (but not identical to) another recently posted problem



I'm trying to set up a macro that will allow me to select a range of data
cells dynamically.
The length of the range will vary as shown below:



Val1 10

Val2 20

Val3 50

0 0

0 0

0 0



If I use Rang(A1:B6), all of the above data will be selected, but I'm not
interested in the 0 values. The next time I may have the following results:



Val1 10

Val2 20

Val3 50

Val4 10

0 0

0 0



i.e additional data



I can use the countif function to give me the number of rows which are not
zero, but I cannot combine the above functions (range and countif).

Any ideas?



Thanks,



Sara




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Selecting a dynamic range

Maybe

Dim i As Long

For i = Cells(Rows.Count,"A").End(xlUp).Row
If Cells(i,"A").Value < 0 Then
Exit For
End If
Next i
Range("A1:A" & i).Select

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Alex Nayar" wrote in message
...
Hi

My problem is similar (but not identical to) another recently posted

problem



I'm trying to set up a macro that will allow me to select a range of data
cells dynamically.
The length of the range will vary as shown below:



Val1 10

Val2 20

Val3 50

0 0

0 0

0 0



If I use Rang(A1:B6), all of the above data will be selected, but I'm not
interested in the 0 values. The next time I may have the following

results:



Val1 10

Val2 20

Val3 50

Val4 10

0 0

0 0



i.e additional data



I can use the countif function to give me the number of rows which are not
zero, but I cannot combine the above functions (range and countif).

Any ideas?



Thanks,



Sara






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selecting a dynamic range

set rng = Range(A1").Resize(application.Countif(Range("B:B") ,"<0"),2)
rng.Select

--
Regards,
Tom Ogilvy


"Alex Nayar" wrote in message
...
Hi

My problem is similar (but not identical to) another recently posted

problem



I'm trying to set up a macro that will allow me to select a range of data
cells dynamically.
The length of the range will vary as shown below:



Val1 10

Val2 20

Val3 50

0 0

0 0

0 0



If I use Rang(A1:B6), all of the above data will be selected, but I'm not
interested in the 0 values. The next time I may have the following

results:



Val1 10

Val2 20

Val3 50

Val4 10

0 0

0 0



i.e additional data



I can use the countif function to give me the number of rows which are not
zero, but I cannot combine the above functions (range and countif).

Any ideas?



Thanks,



Sara






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Selecting a dynamic range

You need to create an indirect reference from your countif function. It will
look similar to: Indirect(concatenate("A1:B",COUNTIF(B1:B2000,"0") ))

"Alex Nayar" wrote:

If I use Range(A1:B6), all of the above data will be selected, but I'm not
interested in the 0 values. The next time I may have the following results:



Val1 10

Val2 20

Val3 50

Val4 10

0 0

0 0



i.e additional data



I can use the countif function to give me the number of rows which are not
zero, but I cannot combine the above functions (range and countif).

Any ideas?



Thanks,



Sara





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Selecting a dynamic range

Tom,

I've just got to jump in and say that's a nice bit of code!

Doug

"Tom Ogilvy" wrote in message
...
set rng = Range(A1").Resize(application.Countif(Range("B:B") ,"<0"),2)
rng.Select

--
Regards,
Tom Ogilvy


"Alex Nayar" wrote in message
...
Hi

My problem is similar (but not identical to) another recently posted

problem



I'm trying to set up a macro that will allow me to select a range of

data
cells dynamically.
The length of the range will vary as shown below:



Val1 10

Val2 20

Val3 50

0 0

0 0

0 0



If I use Rang(A1:B6), all of the above data will be selected, but I'm

not
interested in the 0 values. The next time I may have the following

results:



Val1 10

Val2 20

Val3 50

Val4 10

0 0

0 0



i.e additional data



I can use the countif function to give me the number of rows which are

not
zero, but I cannot combine the above functions (range and countif).

Any ideas?



Thanks,



Sara










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selecting a dynamic range

Thanks. Just hope it works/solves the problem.

--
Regards,
Tom Ogilvy

"Doug Glancy" wrote in message
...
Tom,

I've just got to jump in and say that's a nice bit of code!

Doug

"Tom Ogilvy" wrote in message
...
set rng = Range(A1").Resize(application.Countif(Range("B:B") ,"<0"),2)
rng.Select

--
Regards,
Tom Ogilvy


"Alex Nayar" wrote in message
...
Hi

My problem is similar (but not identical to) another recently posted

problem



I'm trying to set up a macro that will allow me to select a range of

data
cells dynamically.
The length of the range will vary as shown below:



Val1 10

Val2 20

Val3 50

0 0

0 0

0 0



If I use Rang(A1:B6), all of the above data will be selected, but I'm

not
interested in the 0 values. The next time I may have the following

results:



Val1 10

Val2 20

Val3 50

Val4 10

0 0

0 0



i.e additional data



I can use the countif function to give me the number of rows which are

not
zero, but I cannot combine the above functions (range and countif).

Any ideas?



Thanks,



Sara










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
Selecting range in list of range names depending on a cell informa Courreges Excel Discussion (Misc queries) 2 June 19th 06 10:59 AM
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
selecting a dynamic range Alan M Excel Programming 1 August 17th 05 10:57 AM
Selecting and copying a dynamic range of cells EstherJ Excel Programming 2 August 11th 05 06:07 PM
Selecting & Pasting Dynamic Ranges GerryM[_2_] Excel Programming 4 November 17th 04 09:12 AM


All times are GMT +1. The time now is 01:17 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"