Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
JCP
 
Posts: n/a
Default Selecting rows based on criteria

Hi,

I am relatively new to macros, and need help with regard to selecting rows
in Excel.

1. I currently have a macro which sorts a pre-defined range of 100 rows.
However there is only data in about 50 of these rows (although this exact
figure varies. On certain days there will be 60 rows, but never more than 100
rows).

2. The macro then copies the sort range and pastes the values elsewhere.

The problem is that one of the sort criteria is a field that contains both
numbers and text. So the result of the macro is (e.g.) 25 rows of numbers,
then 50 rows of blank space, and then 25 rows of text.

What I need the macro to do is (in step 2. above) only select rows that
contain data, so that the pasted values data will only contain 50 rows of
data, rather than 100.

I am sure there is an easy way to do this using countloop or something, but
I am not experienced to know how to use this.

Any suggestions would be much appreciated.

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.misc
robert111
 
Posts: n/a
Default Selecting rows based on criteria


if you sort ascending - numbers come before text come before blanks,
I just tried it.


--
robert111
------------------------------------------------------------------------
robert111's Profile: http://www.excelforum.com/member.php...o&userid=31996
View this thread: http://www.excelforum.com/showthread...hreadid=529509

  #3   Report Post  
Posted to microsoft.public.excel.misc
FSt1
 
Posts: n/a
Default Selecting rows based on criteria

hi,
selecting row that only contain data.
I am assuming that you have a solid block of data with no blank rows and
your data start in cell A1.
note: if your are adding new and unfamiliar code, it is always a good idea
to create a test module and play with the new code to make sure that it is
doing what you want before adding it to your macro perticularly if you have
to modify the new code.

remove the copy range sniplet from you code and insert this instead.

Range(Range("A65500").End(xlUp), _
Range("A65500").End(xlUp).End(xlUp).Offset(0, 2)).Select
Selection.copy

This will select only the rows that have data regardless of how many rows.
the above sniplet only select the first 3 columns so you will need to change
the offset to the number of columns you have minus 1. the first number is
rows, second is columns. if you have 10 columns then offset(0, 9).
robert111 is right about the sort of numbers and text. not much you can do
about that.
if you want to resize the range each time you run the code add this after
the above sniplet.

ActiveWorkbook.Names.Add Name:="MyRange", RefersTo:= _
Selection

you will have to change the name from MyRange to your range name.

good luck
FSt1


"JCP" wrote:

Hi,

I am relatively new to macros, and need help with regard to selecting rows
in Excel.

1. I currently have a macro which sorts a pre-defined range of 100 rows.
However there is only data in about 50 of these rows (although this exact
figure varies. On certain days there will be 60 rows, but never more than 100
rows).

2. The macro then copies the sort range and pastes the values elsewhere.

The problem is that one of the sort criteria is a field that contains both
numbers and text. So the result of the macro is (e.g.) 25 rows of numbers,
then 50 rows of blank space, and then 25 rows of text.

What I need the macro to do is (in step 2. above) only select rows that
contain data, so that the pasted values data will only contain 50 rows of
data, rather than 100.

I am sure there is an easy way to do this using countloop or something, but
I am not experienced to know how to use this.

Any suggestions would be much appreciated.

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.misc
JCP
 
Posts: n/a
Default Selecting rows based on criteria

Hi,

Unfortunately, although the block of data I wish to copy contains no blank
rows, the xlEnd will not work as beneath the block of data I want to copy are
other rows with formulae in.

So I am still stuck!

"FSt1" wrote:

hi,
selecting row that only contain data.
I am assuming that you have a solid block of data with no blank rows and
your data start in cell A1.
note: if your are adding new and unfamiliar code, it is always a good idea
to create a test module and play with the new code to make sure that it is
doing what you want before adding it to your macro perticularly if you have
to modify the new code.

remove the copy range sniplet from you code and insert this instead.

Range(Range("A65500").End(xlUp), _
Range("A65500").End(xlUp).End(xlUp).Offset(0, 2)).Select
Selection.copy

This will select only the rows that have data regardless of how many rows.
the above sniplet only select the first 3 columns so you will need to change
the offset to the number of columns you have minus 1. the first number is
rows, second is columns. if you have 10 columns then offset(0, 9).
robert111 is right about the sort of numbers and text. not much you can do
about that.
if you want to resize the range each time you run the code add this after
the above sniplet.

ActiveWorkbook.Names.Add Name:="MyRange", RefersTo:= _
Selection

you will have to change the name from MyRange to your range name.

good luck
FSt1


"JCP" wrote:

Hi,

I am relatively new to macros, and need help with regard to selecting rows
in Excel.

1. I currently have a macro which sorts a pre-defined range of 100 rows.
However there is only data in about 50 of these rows (although this exact
figure varies. On certain days there will be 60 rows, but never more than 100
rows).

2. The macro then copies the sort range and pastes the values elsewhere.

The problem is that one of the sort criteria is a field that contains both
numbers and text. So the result of the macro is (e.g.) 25 rows of numbers,
then 50 rows of blank space, and then 25 rows of text.

What I need the macro to do is (in step 2. above) only select rows that
contain data, so that the pasted values data will only contain 50 rows of
data, rather than 100.

I am sure there is an easy way to do this using countloop or something, but
I am not experienced to know how to use this.

Any suggestions would be much appreciated.

Thanks

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
Insert rows based on specific value bob Excel Worksheet Functions 6 February 29th 08 07:11 PM
Selecting rows based on cell entries m.cain Excel Worksheet Functions 3 March 24th 06 04:56 PM
Selecting rows based on cell entries m.cain Excel Discussion (Misc queries) 2 March 24th 06 10:46 AM
hide rows based on cell value dummster New Users to Excel 1 February 15th 06 11:37 PM
format group of rows based on condition Aaron Excel Discussion (Misc queries) 0 January 10th 06 12:29 AM


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