Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
jesmin
 
Posts: n/a
Default Why code for find() is not working


Hello Anyone:
Best wishes. I have an excel report sheet that contains 3 sets of data
in tabular form. For each set, I will find maximum value and will
highlight the cell. This maximum value is in columns b,d,f,h and j. I
am selecting each set of data as sepatre range and finding and
highlighting my cell.
----------code
range1.select
with selection
set
fndcell=cells.find(what:=val,after:=activecell,loo kin:=xlvalues,lookat:=xlpart(orxlwhole),searchorde r:=xlbycolumns,searchdirection:=xlnext,matchcase:= true).
end with
problem:
I have a max value in both 1st and 2nd set.(say 500). In my 2nd loop,
though I am selecting 2nd range, its finding the 500 max value from
range1(for set1 data) and highlighting it. The range2 selection is fine
but .find() is going outside the selection and trying to see the data
there.
what is the wrong in my code.Is the problem in the find() cluase?
Thanks in advance


--
jesmin
------------------------------------------------------------------------
jesmin's Profile: http://www.excelforum.com/member.php...o&userid=29540
View this thread: http://www.excelforum.com/showthread...hreadid=496471

  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Why code for find() is not working

It's probably best to copy the code directly from the VBE and paste into your
message. Lots of stuff can get lost if you just type in the compose window (of
excelforum).

You've got a couple of typos in that line and it's difficult to guess whether
the typo is in your code or just in your post.

set fndcell = .cells... (notice the leading dot)

the lookat:= is one of those--not what you posted.

But this kind of code worked ok for me:

Option Explicit
Sub HighlightMax()

Dim myRng As Range
Dim wks As Worksheet
Dim myMax As Double
Dim myCol As Range
Dim FoundCell As Range
Set wks = ActiveSheet

With wks
Set myRng = .Range("b1,d1,f1,h1,j1").EntireColumn
For Each myCol In myRng.Columns
With myCol
myMax = Application.Max(.Cells)
Set FoundCell = .Find(what:=myMax, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext)
If FoundCell Is Nothing Then
'do nothing (all text???)
Else
FoundCell.Interior.ColorIndex = 6
End If
End With
Next myCol
End With

End Sub


jesmin wrote:

Hello Anyone:
Best wishes. I have an excel report sheet that contains 3 sets of data
in tabular form. For each set, I will find maximum value and will
highlight the cell. This maximum value is in columns b,d,f,h and j. I
am selecting each set of data as sepatre range and finding and
highlighting my cell.
----------code
range1.select
with selection
set
fndcell=cells.find(what:=val,after:=activecell,loo kin:=xlvalues,lookat:=xlpart(orxlwhole),searchorde r:=xlbycolumns,searchdirection:=xlnext,matchcase:= true).
end with
problem:
I have a max value in both 1st and 2nd set.(say 500). In my 2nd loop,
though I am selecting 2nd range, its finding the 500 max value from
range1(for set1 data) and highlighting it. The range2 selection is fine
but .find() is going outside the selection and trying to see the data
there.
what is the wrong in my code.Is the problem in the find() cluase?
Thanks in advance

--
jesmin
------------------------------------------------------------------------
jesmin's Profile: http://www.excelforum.com/member.php...o&userid=29540
View this thread: http://www.excelforum.com/showthread...hreadid=496471


--

Dave Peterson
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
Complicated If Then / V Lookup / Match Statement... ryesworld Excel Worksheet Functions 17 December 10th 05 02:09 PM
Need 2 add second then third code with first code in the Tab View nick s Excel Worksheet Functions 3 December 6th 05 02:20 AM
Conform a total to a list of results? xmaveric Excel Discussion (Misc queries) 1 August 21st 05 07:22 PM
Macro for changing text to Proper Case JPriest Excel Worksheet Functions 3 August 8th 05 09:31 PM
Often-Used Code not working in a new Workbook Steve Excel Discussion (Misc queries) 2 December 16th 04 11:55 PM


All times are GMT +1. The time now is 03:18 AM.

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

About Us

"It's about Microsoft Excel"