Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Find Method question...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bramnizzle@gmail.com - 26 Nov 2007 00:16 GMT
I found this bit of code on the internet.

Copy all the rows that have the value 1000 in column D and paste to
Sheet2:
Find_Range(1000, Columns("D"), xlFormulas, xlWhole).EntireRow.Copy
Range("Sheet2!A1")

This finds the value 1000 in column D.  I want to be able to find a
negative value in column D.

Any clue?
Dave Peterson - 26 Nov 2007 01:16 GMT
If your data is all numeric and is formatted to show negatives using minus
signs, maybe you could look for -.

If both those things aren't true, then I think you'll have to loop through the
cells.

You may be able to reduce the cells to loop through by looking at just the
numeric cells in column D.

If your data is all constants (no formulas):

dim myRng as range
dim myCell as range

set myrng = nothing
on error resume next
set myrng = worksheets("sheet999").range("d:d") _
    .cells.specialcells(xlcelltypeconstants, xlnumbers)
on error goto 0

if myrng is nothing then
 msgbox "No numbers!
else
 for each mycell in myrng.cells
    if mycell.value < 0 then
       'found it, do what you want
    end if
 next mycell
end if

(Untested, uncompiled.  Watch for typos.)

> I found this bit of code on the internet.
>
[quoted text clipped - 7 lines]
>
> Any clue?

Signature

Dave Peterson

bramnizzle@gmail.com - 26 Nov 2007 02:46 GMT
What if they are not all constants (some have formulas)?
Dave Peterson - 26 Nov 2007 03:12 GMT
You could build a giant range (a union of the constants and formulas) or just
look through all the cells.  

dim myRng as range
dim myCell as range

with worksheets("Somesheetnamehere")
 'headers in Row 1???
 set myrng = .range("d2",.cells(.rows.count,"D).end(xlup))
end with

for each mycell in myrng.cells
  if mycell.value < 0 then
      'found it, do what you want
  end if
next mycell

> What if they are not all constants (some have formulas)?

Signature

Dave Peterson

bramnizzle@gmail.com - 26 Nov 2007 03:29 GMT
> You could build a giant range (a union of the constants and formulas) or just
> look through all the cells.
[quoted text clipped - 12 lines]
>    end if
> next mycell

What I meant was, what if the negative numbers I want to find are
formulas?  In other words, the formula produces a negative number.
bramnizzle@gmail.com - 26 Nov 2007 03:43 GMT
Actually, this worked perfect!  Thanks!!!
Dave Peterson - 26 Nov 2007 12:41 GMT
If all the numbers were the results of formulas, you could use this

xlcelltypeformulas
instead of
xlcelltypeconstants

in that previous post.

The problem occurs when you have a mixture of both.

But glad you got it working ok.

> > You could build a giant range (a union of the constants and formulas) or just
> > look through all the cells.
[quoted text clipped - 15 lines]
> What I meant was, what if the negative numbers I want to find are
> formulas?  In other words, the formula produces a negative number.

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.