View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Loop Thru Values in a Column

I see your point. If there are multiple instances, I am just over-writing
them.
--
Gary''s Student
gsnu200705


"Tom Ogilvy" wrote:

To the Original Poster: Was the sheet with data in columns A and AJ the
active sheet when you ran the macro?

Gary, you might want to advance R2 in your code:

Sub ordinate()
Dim i as long, v as String
Dim r2 as Range, lastrow as Long

Set r2 = Sheets("Sheet2").Range("A1")

LastRow = Cells(Cells.Rows.Count, "AJ").End(xlUp).Row

For i = 5 To LastRow
v = Cells(i, "AJ").Value
If v = "D" Or v = "Q" Then
r2.Value = Cells(i, "A").Value
set r2 = r2(2)
End If
Next
End Sub

--
Regards,
Tom Ogilvy


"Gary''s Student" wrote in message
...
Are you certain the column you want searched is AJ??
--
Gary's Student
gsnu200705


"Robert" wrote:

I thought I was there but the LastRow is equal to 1 so nothing is found.
The
actual data does not start until row 5 and there are blanks.
--
Robert Hill



"Gary''s Student" wrote:

How about:

Sub ordinate()

Set r = Range("AJ:AJ")
Set r2 = Sheets("Sheet2").Range("A1")

LastRow = Cells(Cells.Rows.Count, "AJ").End(xlUp).Row

For i = 1 To LastRow
v = Cells(i, "AJ").Value
If v = "D" Or v = "Q" Then
r2.Value = Cells(i, "A").Value
End If
Next
End Sub

--
Gary's Student
gsnu200705


"Robert" wrote:

I need to loop thru values in a secific column such as 'AJ'. When I
find a
'D', or a 'Q', I want to put the name of the perosn in column A into
another
spreadsheet. I find examples of summing values in a column but not
locating
cerain values.

Thanks for assistance...
--
Robert Hill