Thread: Select Range
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Charabeuh[_4_] Charabeuh[_4_] is offline
external usenet poster
 
Posts: 62
Default Select Range

hello,

another way without loop:
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''
Sub Test()
Dim VisibleCells As Range
Application.ScreenUpdating = False
With ActiveSheet
If .AutoFilterMode Then .Cells.AutoFilter
.Range("A1:A1000").AutoFilter Field:=1, Criteria1:="=*SAFEWAY*"
If InStr(1, .Cells(1, 1), "SAFEWAY", vbTextCompare) Then .Cells(2, 4)
= .Cells(2, 4) - Cells(1, 2)
Set VisibleCells = .Range("B2:B1000").SpecialCells(xlCellTypeVisible)
.Cells(2, 4) = .Cells(2, 4) -
Application.WorksheetFunction.Subtotal(9, VisibleCells)
If .AutoFilterMode Then .Cells.AutoFilter
End With
Application.ScreenUpdating = False
End Sub





"Ali" a écrit dans le message de groupe de
discussion :
...
I want to select a cell that contain a specific word in it: I have
written as follow:
Sub Test()

Cells(2, 4) = 0
For i = 1 To 1000

If Cells(i, 1).Contain "SAFEWAY" Then
Cells(2, 4) = Cells(2, 4) - Cells(i, 2)
End If

Next i

End Sub

But it does't work
could you please make it correct for me.
Thanks
Ali