Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default Finding TWO things

Hi

I got this code example form Excel Help

--
With Worksheets(1).Range("a1:a500")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
--

I know this finds the value 2 and changes it to 5. Could this
be changed so it finds either 2 OR 3 ?

I don't need to change anything to 5, just want to build an
array of row numbers where there's 2 or 5.

(The 2 and 5 here are examples, eventually I want to find any two
strings with this method).

Thanks for any help.
Cheers - Kirk
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Finding TWO things

thats why we use parameters...

Option Explicit
Sub Demo()
Setto5 2
Setto5 3
End Sub



Sub Setto5(val As String)
Dim c As Range
Dim firstAddress As String
With Worksheets(1).Range("a1:a500")
Set c = .Find(val, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext()
Loop While Not c Is Nothing
End If
End With
End Sub




"kirkm" wrote in message ...
Hi

I got this code example form Excel Help

--
With Worksheets(1).Range("a1:a500")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
--

I know this finds the value 2 and changes it to 5. Could this
be changed so it finds either 2 OR 3 ?

I don't need to change anything to 5, just want to build an
array of row numbers where there's 2 or 5.

(The 2 and 5 here are examples, eventually I want to find any two
strings with this method).

Thanks for any help.
Cheers - Kirk

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default Finding TWO things

On Sun, 24 May 2009 10:44:18 +0100, "Patrick Molloy"
wrote:

thats why we use parameters...

Option Explicit
Sub Demo()
Setto5 2
Setto5 3
End Sub


Ah, yess.. but I was hoping to avoid going through the routine twice.

I wonder - probably a silly question - can you use an SQL query in
Excel e.g. with a criteria Like *2* or Like *3* ?


Thanks - Kirk
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default Finding TWO things

This is not so efficient way, because of checking every cells. but try
Sub test below. Sub test below calls FindRowNum that returns a array of
row's number satisfying criteria(*2* or *3*) in the range("A1:A500").

FindRowNum is a function to return a array of row's number satisfying
criteria *2* or *3* within some range.

Sub test()
Dim v As Variant
v = FindRowNum(Range("A1:A500"))
For i = 0 To UBound(v)
MsgBox v(i)
Next
End Sub

Function FindRowNum(rng As Range) As Variant
Dim arr() As Long, i As Long
Dim R As Range

ReDim arr(rng.Cells.Count - 1)

For Each R In rng
If R.Value Like "*2*" Or R.Value Like "*3*" Then
arr(i) = R.Row
i = i + 1
End If
Next
ReDim Preserve arr(i - 1)
FindRowNum = arr
End Function

Keiji

kirkm wrote:
On Sun, 24 May 2009 10:44:18 +0100, "Patrick Molloy"
wrote:

thats why we use parameters...

Option Explicit
Sub Demo()
Setto5 2
Setto5 3
End Sub


Ah, yess.. but I was hoping to avoid going through the routine twice.

I wonder - probably a silly question - can you use an SQL query in
Excel e.g. with a criteria Like *2* or Like *3* ?


Thanks - Kirk

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A few things Bryan De-Lara[_2_] Excel Worksheet Functions 6 November 3rd 08 04:58 PM
######THEY DO DIFFERENT THINGS TO GET IT############# keerthi Charts and Charting in Excel 0 April 30th 08 07:45 AM
two things at once? evanzo Excel Programming 2 November 29th 05 01:08 PM
2 things Srikanth Veera Excel Programming 2 September 26th 04 11:48 PM
2 things Michael Wise Excel Programming 6 March 5th 04 07:25 AM


All times are GMT +1. The time now is 09:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"