Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
excelnovice
 
Posts: n/a
Default How to use macros to copy a range of cells which can exclude some cells which I didn't want to be copied?

For example if I have data like this:

Eggs
NIL
Ham
Bacon
NIL
Cheese
Salmon
Chicken
Turkey
NIL


I want to use macros to copy the cells which will exclude cells which
has NIL... to give me this:

Eggs
Ham
Bacon
Cheese
Salmon
Chicken
Turkey

How can i do it? The only thing I know here is to use
Range("A1:A10").Copy........ which will always include NIL......

  #2   Report Post  
Gary''s Student
 
Posts: n/a
Default

Put your data in column A and run this tiny macro:

Sub novice()
j = 1
For i = 1 To 10
If Cells(i, 1) = "NIL" Then
Else
Cells(j, 2) = Cells(i, 1)
j = j + 1
End If
Next
End Sub


and your copy will be in column B

Have a good day
--
Gary''s Student


"excelnovice" wrote:

For example if I have data like this:

Eggs
NIL
Ham
Bacon
NIL
Cheese
Salmon
Chicken
Turkey
NIL


I want to use macros to copy the cells which will exclude cells which
has NIL... to give me this:

Eggs
Ham
Bacon
Cheese
Salmon
Chicken
Turkey

How can i do it? The only thing I know here is to use
Range("A1:A10").Copy........ which will always include NIL......


  #3   Report Post  
Richard Buttrey
 
Posts: n/a
Default

On 24 Sep 2005 11:51:20 -0700, "excelnovice"
wrote:

For example if I have data like this:

Eggs
NIL
Ham
Bacon
NIL
Cheese
Salmon
Chicken
Turkey
NIL


I want to use macros to copy the cells which will exclude cells which
has NIL... to give me this:

Eggs
Ham
Bacon
Cheese
Salmon
Chicken
Turkey

How can i do it? The only thing I know here is to use
Range("A1:A10").Copy........ which will always include NIL......



The easiest way without macros is to filter your list using the 'does
not contain' "NIL" option, highlight the range, Copy and then Paste
somewhere else.

If you really want to use a macro then you could get it to do the same
thing.

HTH

__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________
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
Match function...random search? Les Excel Worksheet Functions 10 July 28th 05 11:54 AM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 2 May 2nd 05 08:53 AM
Using Command Button to copy cells Pennington Excel Discussion (Misc queries) 1 April 29th 05 02:30 AM
Copy cells into range of cells until cell change mdeanda Excel Worksheet Functions 1 April 22nd 05 08:41 PM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 0 April 7th 05 12:47 AM


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