Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do I create a list from another list with exclusions (such as blank cells)?

I would really appreciate some help with this. I've done a fair
amount of googling and only come up with partial solutions.

Scenario:
2 worksheets in a workbook. Worksheet 1, column A, contains values
and blank cells at random. Worksheet 2 needs to compile a list, in
order of appearance, all values from Worksheet 1's column A with two
exclusions. The first exclusion being blank cells (null values). The
second exclusion, for example, being the value of "1".

Can this be done with an array formula in Worksheet 2? Will this
require VBA? Any example code would be much appreciated.

Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 417
Default How do I create a list from another list with exclusions (such as blank cells)?

I think I would first try to solve this problem using a pivot table. On
worksheet 1, make sure that column A has a column label in row 1 (i.e.
"Data"?). Then add the formula "=row(A2)" in column B (column label "Row"),
and fill all the way down the worksheet.

Create a pivot table on worksheet 2, with column A as a row field (on the
left side), and use the minimum of column B as the data field, with the
pivot table sorted by data (column B minimum) rather than by the row field
(list of column A values). Click on the row field, and turn the check boxes
for "1" and "blanks" off.

You could write a VBA routine to do this, if you want (use the macro
recorder to get started).

--
Regards,
Bill Renaud



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do I create a list from another list with exclusions (such as blank cells)?

On Oct 2, 12:33 am, "Bill Renaud"
wrote:
I think I would first try to solve this problem using a pivot table. On
worksheet 1, make sure that column A has a column label in row 1 (i.e.
"Data"?). Then add the formula "=row(A2)" in column B (column label "Row"),
and fill all the way down the worksheet.

Create a pivot table on worksheet 2, with column A as a row field (on the
left side), and use the minimum of column B as the data field, with the
pivot table sorted by data (column B minimum) rather than by the row field
(list of column A values). Click on the row field, and turn the check boxes
for "1" and "blanks" off.

You could write a VBA routine to do this, if you want (use the macro
recorder to get started).

--
Regards,
Bill Renaud


I'm not sure I entirely follow you here, so I wasn't able to try your
solution to a tee. However, I did try using a pivot table in a hidden
area, and I could exclude the two values (blank included) that I
didn't want. I could have then linked the values of the cells in the
pivot table to the cells on "Worksheet 2" to effectively accomplish
the task at hand (however messy it is). However, the table would only
return unique values. I often have multiple instances of the same
value in my situation, so this would not work for me.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 417
Default How do I create a list from another list with exclusions (such as blank cells)?

Sorry I misunderstood your problem. I assumed (wrongly!) that you wanted a
unique set of values on worksheet 2.

Try the following code to do what you want.

'----------------------------------------------------------------------
Public Sub CopyListWithExclusions()
Dim wsData As Worksheet
Dim wsNew As Worksheet
Dim rngData As Range
Dim rngCell As Range
Dim lngCellsCopied As Long

Set wsData = ActiveSheet
'Add new worksheet and place after the active worksheet.
Set wsNew = ActiveWorkbook.Worksheets.Add
wsNew.Move After:=wsData

Set rngData = wsData.UsedRange

lngCellsCopied = 0
For Each rngCell In rngData
If Not IsEmpty(rngCell) _
Then
'Cell is not empty, so check value and copy, if necessary.
'Simply add more values to Case 1 to skip copying those values.
'(i.e. Case 1, 5, 7)
Select Case rngCell.Value
Case 1
'Do not copy.
Case Else
lngCellsCopied = lngCellsCopied + 1
rngCell.Copy Destination:=wsNew.Cells(lngCellsCopied, 1)
End Select
End If
Next rngCell
End Sub

--
Regards,
Bill Renaud



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 417
Default How do I create a list from another list with exclusions (such as blank cells)?

If you have lots of data (hundreds or thousands of rows), then you might
want to add the following line somewhere at the top of the program (I
forgot to add it):

Application.ScreenUpdating = False

--
Regards,
Bill Renaud





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
create new list from list A, but with exclusions from a list B Harold Good Excel Worksheet Functions 3 April 11th 08 11:23 PM
No colour in cells when blank in list harwookf Excel Worksheet Functions 1 November 15th 07 08:58 PM
Eliminate Blank Rown in a List - Then Create New List geither Excel Discussion (Misc queries) 1 December 14th 06 07:51 PM
Condensing a list/range with blank cells to a new list/range without blanks KR Excel Worksheet Functions 4 July 5th 05 04:23 PM
Naming list of non blank cells DynamiteSkippy Excel Programming 2 May 31st 05 11:47 PM


All times are GMT +1. The time now is 03:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"