Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
....is this any better?
Rgds J Sub guided_copy_to_followup() lastrow = Cells(Rows.Count, 1).End(xlUp).Row b = 2 For a = 1 To lastrow If Cells(a, 9) = "Follow Up Immediately" _ Then Range("A" & a & ":D" & 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 & ":D" & a).Copy Sheets("upcoming follow-ups").Range("A" & b) b = b + 1 End If If Cells(a, 9) = "Follow Up in 2 Days" _ Then Range("A" & a & ":D" & a).Copy Sheets("upcoming follow-ups").Range("A" & b) b = b + 1 End If Next a End Sub On Oct 23, 5:53 am, Bob wrote: 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 doesn't 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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you. The code works perfectly.
I have one other issue I would appreciate any possible help with. I have another workbook that I am trying to do a similar process with except copy and paste noncontiguous cells in one sheet(€śmotivation€ť) to columns in another sheet(€śfollowup€ť). The workbooks are set up very similar to each other so I was assuming that the codes would be similar but I cant quite get it to work. If column I of Motivation says €śFollow Up Immediately€ť, €śFollow Up in 1 Day€ť, or €śFollow Up in 2 Days€ť then I am trying to copy cells A:D, F:H, J, U, W of that row into columns A:J of the next blank row of the sheet Followup. Any help in modifying the code for the previous workbook or if that isnt possible creating new code for this task would be greatly appreciated. --Bob "WhytheQ" wrote: ....is this any better? Rgds J Sub guided_copy_to_followup() lastrow = Cells(Rows.Count, 1).End(xlUp).Row b = 2 For a = 1 To lastrow If Cells(a, 9) = "Follow Up Immediately" _ Then Range("A" & a & ":D" & 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 & ":D" & a).Copy Sheets("upcoming follow-ups").Range("A" & b) b = b + 1 End If If Cells(a, 9) = "Follow Up in 2 Days" _ Then Range("A" & a & ":D" & a).Copy Sheets("upcoming follow-ups").Range("A" & b) b = b + 1 End If Next a End Sub On Oct 23, 5:53 am, Bob wrote: 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 doesn't 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I reckon it'll be almost the same. Maybe the following will work?!
Rgds J Sub guided_copy_to_followup() lastrow = Cells(Rows.Count, 1).End(xlUp).Row b = 2 For a = 1 To lastrow If Cells(a, 9) = "Follow Up Immediately" _ Then Range("A" & a & ":D" & a, "F" & a & ":H" & a, "J" & a, "U" & a, "W" & a).Copy Sheets("followup").Range("A" & b & ":J" & b) b = b + 1 End If If Cells(a, 9) = "Follow Up in 1 Day" _ Then Range("A" & a & ":D" & a, "F" & a & ":H" & a, "J" & a, "U" & a, "W" & a).Copy Sheets("followup").Range("A" & b & ":J" & b) b = b + 1 End If If Cells(a, 9) = "Follow Up in 2 Days" _ Then Range("A" & a & ":D" & a, "F" & a & ":H" & a, "J" & a, "U" & a, "W" & a).Copy Sheets("followup").Range("A" & b & ":J" & b) b = b + 1 End If Next a End Sub On Oct 25, 7:54 am, Bob wrote: Thank you. The code works perfectly. I have one other issue I would appreciate any possible help with. I have another workbook that I am trying to do a similar process with except copy and paste noncontiguous cells in one sheet("motivation") to columns in another sheet("followup"). The workbooks are set up very similar to each other so I was assuming that the codes would be similar but I can't quite get it to work. If column I of Motivation says "Follow Up Immediately", "Follow Up in 1 Day", or "Follow Up in 2 Days" then I am trying to copy cells A:D, F:H, J, U, W of that row into columns A:J of the next blank row of the sheet Followup. Any help in modifying the code for the previous workbook or if that isn't possible creating new code for this task would be greatly appreciated. --Bob "WhytheQ" wrote: ....is this any better? Rgds J Sub guided_copy_to_followup() lastrow = Cells(Rows.Count, 1).End(xlUp).Row b = 2 For a = 1 To lastrow If Cells(a, 9) = "Follow Up Immediately" _ Then Range("A" & a & ":D" & 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 & ":D" & a).Copy Sheets("upcoming follow-ups").Range("A" & b) b = b + 1 End If If Cells(a, 9) = "Follow Up in 2 Days" _ Then Range("A" & a & ":D" & a).Copy Sheets("upcoming follow-ups").Range("A" & b) b = b + 1 End If Next a End Sub On Oct 23, 5:53 am, Bob wrote: 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 doesn't 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- Hide quoted text -- Show quoted text - |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
J,
Thanks for the code unfortunately its not quite working correctly. When I run it I get a €śCompile error: Wrong number of arguments or invalid property assignment€ť message. I have tried to do some tweaking to it and believe that part of the problem may be that the Ranges are too long. If I alter the ranges to only contain two arguments as follows then it runs without the error message. Range("A" & a & ":D" & a, "F" & a).Copy Sheets("followup ").Range("A" & b & ":J" & b) However, this obviously only copies columns A:F instead of producing the original desired results of copying columns A, B, C, D, F, G, H, J, U, & W. Additionally, column E is copied with the altered code which I cannot figure out why because it is not included in the specified range. Once again, any suggestions on how to fix the code would be greatly appreciated. Thanks, --Bob "WhytheQ" wrote: I reckon it'll be almost the same. Maybe the following will work?! Rgds J Sub guided_copy_to_followup() lastrow = Cells(Rows.Count, 1).End(xlUp).Row b = 2 For a = 1 To lastrow If Cells(a, 9) = "Follow Up Immediately" _ Then Range("A" & a & ":D" & a, "F" & a & ":H" & a, "J" & a, "U" & a, "W" & a).Copy Sheets("followup").Range("A" & b & ":J" & b) b = b + 1 End If If Cells(a, 9) = "Follow Up in 1 Day" _ Then Range("A" & a & ":D" & a, "F" & a & ":H" & a, "J" & a, "U" & a, "W" & a).Copy Sheets("followup").Range("A" & b & ":J" & b) b = b + 1 End If If Cells(a, 9) = "Follow Up in 2 Days" _ Then Range("A" & a & ":D" & a, "F" & a & ":H" & a, "J" & a, "U" & a, "W" & a).Copy Sheets("followup").Range("A" & b & ":J" & b) b = b + 1 End If Next a End Sub On Oct 25, 7:54 am, Bob wrote: Thank you. The code works perfectly. I have one other issue I would appreciate any possible help with. I have another workbook that I am trying to do a similar process with except copy and paste noncontiguous cells in one sheet("motivation") to columns in another sheet("followup"). The workbooks are set up very similar to each other so I was assuming that the codes would be similar but I can't quite get it to work. If column I of Motivation says "Follow Up Immediately", "Follow Up in 1 Day", or "Follow Up in 2 Days" then I am trying to copy cells A:D, F:H, J, U, W of that row into columns A:J of the next blank row of the sheet Followup. Any help in modifying the code for the previous workbook or if that isn't possible creating new code for this task would be greatly appreciated. --Bob "WhytheQ" wrote: ....is this any better? Rgds J Sub guided_copy_to_followup() lastrow = Cells(Rows.Count, 1).End(xlUp).Row b = 2 For a = 1 To lastrow If Cells(a, 9) = "Follow Up Immediately" _ Then Range("A" & a & ":D" & 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 & ":D" & a).Copy Sheets("upcoming follow-ups").Range("A" & b) b = b + 1 End If If Cells(a, 9) = "Follow Up in 2 Days" _ Then Range("A" & a & ":D" & a).Copy Sheets("upcoming follow-ups").Range("A" & b) b = b + 1 End If Next a End Sub On Oct 23, 5:53 am, Bob wrote: 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 doesn't 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- Hide quoted text -- Show quoted text - |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Copying rows with specific criteria | Excel Discussion (Misc queries) | |||
Copying Data from one sheet to another sheet on a specific day | Excel Worksheet Functions | |||
Copying specific cells from a sheet to another | Excel Discussion (Misc queries) | |||
Copying Specific Values From Sheet | Excel Discussion (Misc queries) | |||
Copying specific rows from one sheet to another | Excel Programming |