Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You would get that behavior if there are no codes in column AJ. If there
are code in AJ, then the code should work with the correction for advancing R2. You added explantation has done nothing to explain why you have no codes in AJ. This hard codes lastrow at 50 Sub ordinate() Dim i as long, v as String Dim r2 as Range, lastrow as Long Set r2 = Sheets("Sheet2").Range("A1") LastRow = 50 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 but if there are no codes in AJ, then it won't make much difference. -- Regards, Tom Ogilvy "Robert" wrote in message ... The spreadsheet is for O.R. scheduling and it covers a 6 week period (42 days). Column A is for nurses names. Day 1 is column B and the last day is column AQ. The user will select a day for a report to be run. There are appoximately 41 nurses on the spreadsheet from A5 to the A44 with some blanks. Therefor, if the user chooses the day for column AJ, then I need to list all nurses with a code of 'D' or 'Q' or a variety of other codes that fall in that column (or day). If I use the code suggested for LastRow, I get the number 1 and the loop does not get the names. If I change .End(xlUp).row to .End(xlDown).row the LastRow will be 65536 and the loop will run but I will have to lop through that number for every codes I need. Sorry for the length of this but I don't think I explained myself very well previoulsy. -- Robert Hill "Gary''s Student" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Autosum column values, if separate column values equal certain val | Excel Worksheet Functions | |||
Error loop through #N/A values | Excel Programming | |||
Loop that finds blanks, then subtotals values into different column | Excel Programming | |||
Loop through column headers to search from column name and get cell range | Excel Programming | |||
Calculating values to column D with formula based on values column A | Excel Programming |