View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Problem copying to another sheet with specific criteria

I am having problems with the code below. What I am trying to get it to do
is if the data in any of the cells of column I says €śFollow Up Immediately€ť,
€śFollow Up in 1 Day€ť, or €śFollow Up in 2 Days€ť then copy the data in cells
A:D of that row into the next blank row of another sheet called €śupcoming
follow-ups€ť.

There are two problems with the code in its current form. The first problem
is that it will only copy the data in column A. The second problem is that
when I run the macro I can see it performing the first IF statement correctly
(expect for only copying column A) however when it starts the second and then
the third IF statement it doesnt put them in the next empty row. Instead it
starts at row 2 and overwrites what the previous IF statement did.

Any suggestion on how to modify this code would be greatly appreciated.

--Bob


Sub guided_copy_to_followup()
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
b = 2
c = 2
d = 2

For a = 1 To lastrow
If Cells(a, 9) = "Follow Up Immediately" _
Then
Range("A" & a).Copy Sheets("upcoming follow-ups").Range("A" & b)
b = b + 1
End If
If Cells(a, 9) = "Follow Up in 1 Day" _
Then
Range("A" & a).Copy Sheets("upcoming follow-ups").Range("A" & c)
c = c + 1
End If
If Cells(a, 9) = "Follow Up in 2 Days" _
Then
Range("A" & a).Copy Sheets("upcoming follow-ups").Range("A" & d)
d = d + 1
End If
Next a
End Sub