View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Why use INTERSECT

Steve,

Using the Intersect method can eliminate the need to specify
starting/ending cells...
Application.Intersect(Rows(2), ActiveSheet.UsedRange)

And it can determine common areas between two ranges...
Application.Intersect(Rng1, Rng2)

It is also useful in Worksheet events to determine if a changed cell
falls within a specified range...
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Me.Columns("B"), Target.Cells(1, 1)) Is Nothing Then
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"NHRunner"
wrote in message
I've learned so many features of Excel that I never knew about and I guess
"Intersect" might be the next, but I don't know why or when I would use it.

The following code was given for a particular task. It realize it was code
given in response to another's question but the approach to the task seemed
at bit more complicated than it needed to be so I wondering what benefit
Intersect brought to the table.
My solution is shown below the example code.

'This does not hide columns if the cell is blank or
'if the cell contains text; only if the cell value is not equal to 1...

Sub MakeThemGoAway()
Dim c As Range
Dim varValue As Variant
For Each c In Application.Intersect(ActiveSheet.UsedRange, _
ActiveSheet.Range("A2:BD2")).Cells
varValue = c.Value
If IsNumeric(varValue) Then
If varValue < 1 Then
c.EntireColumn.Hidden = True
End If
End If
Next c
End Sub
--


====================================
For x = firstcol to lastcol
if isnumeric(cellvalue) then
If cellvalue < 1 then
Columns(RtnColLet(x)).EntireColumn.Hidden = true
exit for
end if
end if
next

regards
Steve Moland