View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bill Renaud Bill Renaud is offline
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