View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Vergel Adriano Vergel Adriano is offline
external usenet poster
 
Posts: 857
Default Create Dynamic Range by all cells with the same value

maybe something like this.


Sub test()
Dim rng As Range
Dim lLastRow As Long
Dim lRow As Long
Dim iLastColumn As Integer

lLastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastC ell).Row
iLastColumn = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastC ell).Column

For lRow = 1 To lLastRow
If Cells(lRow, 2).Value = 111 Then
If rng Is Nothing Then
Set rng = Range(Cells(lRow, 1), Cells(lRow, iLastColumn))
Else
Set rng = Union(rng, Range(Cells(lRow, 1), Cells(lRow,
iLastColumn)))
End If
End If
Next lRow

ThisWorkbook.Names.Add "_111", "=" & rng.Address
Set rng = Nothing

End Sub



--
Hope that helps.

Vergel Adriano


"gwhenning" wrote:

I have a spreadsheet that is created from external data. I need to be able to
create a range for all cells matching certain criteria. Not all criteria will
occur every day, and there may be one or many cells containing the same
criteria. For example, Column A contains the Date, and column B contains the
part number. There may be one part number for a given day, or none. I need to
select all cells with part number 111, irregardless of date and create a
named range called 111. I will then create a graph for each named range in my
spreadsheet.