Thread: Select Range
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Excel MVP Don Guillett Excel MVP is offline
external usenet poster
 
Posts: 168
Default Select Range

On Jun 16, 7:24*am, Don Guillett Excel MVP
wrote:
On Jun 15, 11:54*pm, GS wrote:





Per Jessen explained :


This should do it:


Sub Test()


Cells(2, 4) = 0
For i = 1 To 1000
If InStr(1, Cells(i, 1), "SAFEWAY", vbTextCompare) Then
* * Cells(2, 4) = Cells(2, 4) - Cells(i, 2)
End If
Next i
End Sub


Regards,
Per


Another way:


* Sub Test()
* * Dim i As Integer
* * Cells(2, 4) = 0
* * For i = 1 To 1000
* * * If (InStr(Cells(i, 1), "SAFEWAY") 0) Then _
* * * * *Cells(2, 4) = Cells(2, 4) - Cells(i, 2)
* * Next i
* End Sub


regards,


--
Garry


Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Since you said select, this assumes you have only ONE to find and
select
Sub GotoSafewayinColA_SAS()
*Columns("a").Find(What:="safeway", LookIn:=xlValues, _
*LookAt:=xlWhole, SearchOrder:=xlByRows, _
*SearchDirection:=xlNext, MatchCase:=False).Select
End Sub- Hide quoted text -

- Show quoted text -


Quicker than a loop. This finds all in col D and gives your cell(2,4)
total
Sub findAllSafeways()
Set c = Columns("d").Find(what:="safeway", _
LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
FirstAddr = c.Address
Do
Cells(2, 4) = Cells(2, 4) - c.Offset(, -2)
Set c = Columns("A").FindNext(after:=c)
Loop While Not c Is Nothing And c.Address < FirstAddr
End If
End Sub