View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Iain King Iain King is offline
external usenet poster
 
Posts: 32
Default Serching column/range for specified data

For example - Column A contains a date, column B contains misc. data &
column C contains the data that needs to be searched. So I want to be
able to search down column C until the first occurance of the number
"1" is found, then use the date in column A of the same row to
calculate the number of days between that and a date specified
elsewhere in the workbook.


This code does the basics of what you want. You'd have to edit it for
specifics:
I assume no header row, and a date value in every row of the A column.
I use the .Cells(row, column) function, so we use column 1 for A, column 2
for B, etc...


dim r as long
dim lastRow as long
dim foundRow as long
dim searchFor as string

searchFor = "1" ' value to look for
foundRow = 0

with Sheets("Sheet1") 'or whatever sheet name you use
lastRow = .Range("A:A").Count

for r = 1 to lastRow
if .Cells( r, 3).Value = searchFor then
foundRow = r
exit for
endif
next

if foundRow = 0 then 'value not found
exit sub
endif

WorkOutDate( .Cells( foundRow, 1).Value) 'or whatever function you want
to perform on the date held in .Cells( foundRow, 1).Value

end with


Iain King