find a value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need a code that will search Sheet1.column A from A1:A58 and A72:A89 and
return in cell B1 the text "true" if the number "999" is found in the target
range one or more times.
 
Hi Shawn,

Try this:

Sub test()
Dim x As Boolean
With Application
x = (.CountIf(Sheets("Sheet1").Range("A1:A58"), 999) _
+ .CountIf(Sheets("Sheet1").Range("A72:A89"), 999)) > 1
End With
Sheets("Sheet1").Range("B1").Value = x
End Sub

Regards,
KL
 
I used the variation below and it worked. Your way did not. Do you see a
problem with what I have below (it seems to work)

Sub test()
Dim x As Boolean
With Application
x = .CountIf(Sheets("Sheet1").Range("A1:A58"), 999) _
+ .CountIf(Sheets("Sheet1").Range("A72:A89"), 999)
End With
Sheets("Sheet1").Range("B1").Value = x
End Sub

--
Thanks
Shawn


KL said:
Hi Shawn,

Try this:

Sub test()
Dim x As Boolean
With Application
x = (.CountIf(Sheets("Sheet1").Range("A1:A58"), 999) _
+ .CountIf(Sheets("Sheet1").Range("A72:A89"), 999)) > 1
End With
Sheets("Sheet1").Range("B1").Value = x
End Sub

Regards,
KL
 
That should work.

--
Regards,
Tom Ogilvy

Shawn said:
I used the variation below and it worked. Your way did not. Do you see a
problem with what I have below (it seems to work)

Sub test()
Dim x As Boolean
With Application
x = .CountIf(Sheets("Sheet1").Range("A1:A58"), 999) _
+ .CountIf(Sheets("Sheet1").Range("A72:A89"), 999)
End With
Sheets("Sheet1").Range("B1").Value = x
End Sub
 
Hi Shawn,

You are right I mistakenly assumed you wanted TRUE if 999 appeared more than
once.

Regards,
KL


Shawn said:
I used the variation below and it worked. Your way did not. Do you see a
problem with what I have below (it seems to work)

Sub test()
Dim x As Boolean
With Application
x = .CountIf(Sheets("Sheet1").Range("A1:A58"), 999) _
+ .CountIf(Sheets("Sheet1").Range("A72:A89"), 999)
End With
Sheets("Sheet1").Range("B1").Value = x
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top