Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am trying to search a column in my worksheet, and if that column has a
value that is not 1, then compare it to the cell value in the same row in column N. If the two cell values are different then put the current selection in column R. Does that make sense? Here is my code. any help is appreciated! Dim wks As Worksheet Dim rngFound As Range Set wks = Sheets("exam_am_trades") Set rngToSearch = Range("p4:p1700") saddr = ActiveCell.Address Set rngFound = rngToSearch.Find(what:="1", LookIn:=xlValues, lookat:=xlWhole) If rngFound = 1 Then Set rngFound = rngToSearch.FindNext Else If rngFound < saddr.Offset(0, -2) Then saddr.Offset(0, 2) = saddr.Value End If End If End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
John,
The Find method might be even faster, but this works... Jim Cone San Francisco, USA '----------------------------- Sub FindAndEnterValues() Dim rngCell As Range Dim rngToSearch As Excel.Range Dim varValue As Variant Sheets("exam_am_trades").Activate Set rngToSearch = Range("p4:p1700").Cells 'note: rngCell(1, 1) is the cell in column P For Each rngCell In rngToSearch varValue = rngCell.Value If varValue < 1 Then 'Col n If rngCell(1, -1).Value < varValue Then 'Col r rngCell(1, 3).Value = varValue End If End If Next 'rngCell Set rngCell = Nothing Set rngToSearch = Nothing End Sub '---------------------------------- "John" wrote in message I am trying to search a column in my worksheet, and if that column has a value that is not 1, then compare it to the cell value in the same row in column N. If the two cell values are different then put the current selection in column R. Does that make sense? Here is my code. any help is appreciated! Dim wks As Worksheet Dim rngFound As Range Set wks = Sheets("exam_am_trades") Set rngToSearch = Range("p4:p1700") saddr = ActiveCell.Address Set rngFound = rngToSearch.Find(what:="1", LookIn:=xlValues, lookat:=xlWhole) If rngFound = 1 Then Set rngFound = rngToSearch.FindNext Else If rngFound < saddr.Offset(0, -2) Then saddr.Offset(0, 2) = saddr.Value End If End If End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Jim, I will have to compare yours to mine and see why the difference
"Jim Cone" wrote: John, The Find method might be even faster, but this works... Jim Cone San Francisco, USA '----------------------------- Sub FindAndEnterValues() Dim rngCell As Range Dim rngToSearch As Excel.Range Dim varValue As Variant Sheets("exam_am_trades").Activate Set rngToSearch = Range("p4:p1700").Cells 'note: rngCell(1, 1) is the cell in column P For Each rngCell In rngToSearch varValue = rngCell.Value If varValue < 1 Then 'Col n If rngCell(1, -1).Value < varValue Then 'Col r rngCell(1, 3).Value = varValue End If End If Next 'rngCell Set rngCell = Nothing Set rngToSearch = Nothing End Sub '---------------------------------- "John" wrote in message I am trying to search a column in my worksheet, and if that column has a value that is not 1, then compare it to the cell value in the same row in column N. If the two cell values are different then put the current selection in column R. Does that make sense? Here is my code. any help is appreciated! Dim wks As Worksheet Dim rngFound As Range Set wks = Sheets("exam_am_trades") Set rngToSearch = Range("p4:p1700") saddr = ActiveCell.Address Set rngFound = rngToSearch.Find(what:="1", LookIn:=xlValues, lookat:=xlWhole) If rngFound = 1 Then Set rngFound = rngToSearch.FindNext Else If rngFound < saddr.Offset(0, -2) Then saddr.Offset(0, 2) = saddr.Value End If End If End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Compare Cell Values, Offset(-1,0), Offset(-1,-1), and xlFillDefaul | Excel Worksheet Functions | |||
search column, hyperlink, offset, substitute, match (omg) | Excel Discussion (Misc queries) | |||
How do I search excel spreadsheets using multiple search criteria. | Excel Worksheet Functions | |||
Create a search Field within a worksheet to search command buttons | Excel Programming | |||
macro to search and replace with offset | Excel Discussion (Misc queries) |