Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search and Move - Cannot Figure This Out - Please Help
My spreadsheet has 4 columns, for example:
Col A B C D Description Type Charge Offering Alert $35 SO Alert SO Alert 9113 SO Perform $ 5 SO Perform $12 SO Perform 9220 SO Alert $19 SCO Alert 8332 SCO AA i/p $23 SO AA i/p SO I need to: 1) Go through each row of Col D; if it says 'SCO', then go to next row of Col D. 2) If it says 'SO', then a) If Col C 0, add the value in Col C to any other value in Col C (going down) until both Col A and Col B are < blank, and put that sum in Col C on the same row where both Col A and Col B are < blank, then erase the individual entries in Col C used to come to that sum. If during this process you ever find that both Col A and B are blank, then stop and go to the next row in Col D, and start over to see if it says 'SO' or 'SCO'. b) If Col C is blank or = 0, then go to the next row of Col D and start over to see if it says 'SO' or 'SCO'. I've struggled with this for quite some time and am desperately hoping someone can help. The final product, using the example above and afer the macro has run, should look like this: Col A B C D Description Type Charge Offering Alert SO Alert SO Alert 9113 $35 SO Perform SO Perform SO Perform 9220 $17 SO Alert $19 SCO Alert 8332 SCO AA i/p $23 SO AA i/p SO |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search and Move - Cannot Figure This Out - Please Help
Paige
The following macro will do what you want. I think. Try it and post back if I misread what you wrote. HTH Otto Option Explicit Dim First As Range Dim Last As Range Dim c As Long Dim d As Long Sub Whatever() c = 2 Do If Cells(c, 4).Value = "SCO" Then c = c + 1 GoTo NextCell End If If IsEmpty(Cells(c, 3).Value) Or _ Cells(c, 3).Value = 0 Then c = c + 1 GoTo NextCell End If If Cells(c, 3).Value 0 Then _ Set First = Cells(c, 3) For d = 1 To 50 If Not IsEmpty(Cells(c, 1).Offset(d).Value) And _ Not IsEmpty(Cells(c, 2).Offset(d).Value) Then Set Last = Cells(c, 3).Offset(d - 1) c = c + d + 1 Exit For End If If d = 20 Then Exit Sub Next d If Not First Is Nothing And _ Not Last Is Nothing Then Last.Offset(1).Value = Application.Sum(Range(First, Last)) Range(First, Last).ClearContents End If Set First = Nothing Set Last = Nothing NextCell: Loop Until Cells(c, 1).Row Cells(Rows.Count, 1).End(xlUp).Row End Sub "Paige" wrote in message ... My spreadsheet has 4 columns, for example: Col A B C D Description Type Charge Offering Alert $35 SO Alert SO Alert 9113 SO Perform $ 5 SO Perform $12 SO Perform 9220 SO Alert $19 SCO Alert 8332 SCO AA i/p $23 SO AA i/p SO I need to: 1) Go through each row of Col D; if it says 'SCO', then go to next row of Col D. 2) If it says 'SO', then a) If Col C 0, add the value in Col C to any other value in Col C (going down) until both Col A and Col B are < blank, and put that sum in Col C on the same row where both Col A and Col B are < blank, then erase the individual entries in Col C used to come to that sum. If during this process you ever find that both Col A and B are blank, then stop and go to the next row in Col D, and start over to see if it says 'SO' or 'SCO'. b) If Col C is blank or = 0, then go to the next row of Col D and start over to see if it says 'SO' or 'SCO'. I've struggled with this for quite some time and am desperately hoping someone can help. The final product, using the example above and afer the macro has run, should look like this: Col A B C D Description Type Charge Offering Alert SO Alert SO Alert 9113 $35 SO Perform SO Perform SO Perform 9220 $17 SO Alert $19 SCO Alert 8332 SCO AA i/p $23 SO AA i/p SO |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search and Move - Cannot Figure This Out - Please Help
Thanks so much Otto. I am still working and have to get a report out
tonight; will test this first thing tomorrow am and let you know. I really appreciate your help! "Otto Moehrbach" wrote: Paige The following macro will do what you want. I think. Try it and post back if I misread what you wrote. HTH Otto Option Explicit Dim First As Range Dim Last As Range Dim c As Long Dim d As Long Sub Whatever() c = 2 Do If Cells(c, 4).Value = "SCO" Then c = c + 1 GoTo NextCell End If If IsEmpty(Cells(c, 3).Value) Or _ Cells(c, 3).Value = 0 Then c = c + 1 GoTo NextCell End If If Cells(c, 3).Value 0 Then _ Set First = Cells(c, 3) For d = 1 To 50 If Not IsEmpty(Cells(c, 1).Offset(d).Value) And _ Not IsEmpty(Cells(c, 2).Offset(d).Value) Then Set Last = Cells(c, 3).Offset(d - 1) c = c + d + 1 Exit For End If If d = 20 Then Exit Sub Next d If Not First Is Nothing And _ Not Last Is Nothing Then Last.Offset(1).Value = Application.Sum(Range(First, Last)) Range(First, Last).ClearContents End If Set First = Nothing Set Last = Nothing NextCell: Loop Until Cells(c, 1).Row Cells(Rows.Count, 1).End(xlUp).Row End Sub "Paige" wrote in message ... My spreadsheet has 4 columns, for example: Col A B C D Description Type Charge Offering Alert $35 SO Alert SO Alert 9113 SO Perform $ 5 SO Perform $12 SO Perform 9220 SO Alert $19 SCO Alert 8332 SCO AA i/p $23 SO AA i/p SO I need to: 1) Go through each row of Col D; if it says 'SCO', then go to next row of Col D. 2) If it says 'SO', then a) If Col C 0, add the value in Col C to any other value in Col C (going down) until both Col A and Col B are < blank, and put that sum in Col C on the same row where both Col A and Col B are < blank, then erase the individual entries in Col C used to come to that sum. If during this process you ever find that both Col A and B are blank, then stop and go to the next row in Col D, and start over to see if it says 'SO' or 'SCO'. b) If Col C is blank or = 0, then go to the next row of Col D and start over to see if it says 'SO' or 'SCO'. I've struggled with this for quite some time and am desperately hoping someone can help. The final product, using the example above and afer the macro has run, should look like this: Col A B C D Description Type Charge Offering Alert SO Alert SO Alert 9113 $35 SO Perform SO Perform SO Perform 9220 $17 SO Alert $19 SCO Alert 8332 SCO AA i/p $23 SO AA i/p SO |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search and Move - Cannot Figure This Out - Please Help
Otto, works great - thank you SOOOOO....much.
"Otto Moehrbach" wrote: Paige The following macro will do what you want. I think. Try it and post back if I misread what you wrote. HTH Otto Option Explicit Dim First As Range Dim Last As Range Dim c As Long Dim d As Long Sub Whatever() c = 2 Do If Cells(c, 4).Value = "SCO" Then c = c + 1 GoTo NextCell End If If IsEmpty(Cells(c, 3).Value) Or _ Cells(c, 3).Value = 0 Then c = c + 1 GoTo NextCell End If If Cells(c, 3).Value 0 Then _ Set First = Cells(c, 3) For d = 1 To 50 If Not IsEmpty(Cells(c, 1).Offset(d).Value) And _ Not IsEmpty(Cells(c, 2).Offset(d).Value) Then Set Last = Cells(c, 3).Offset(d - 1) c = c + d + 1 Exit For End If If d = 20 Then Exit Sub Next d If Not First Is Nothing And _ Not Last Is Nothing Then Last.Offset(1).Value = Application.Sum(Range(First, Last)) Range(First, Last).ClearContents End If Set First = Nothing Set Last = Nothing NextCell: Loop Until Cells(c, 1).Row Cells(Rows.Count, 1).End(xlUp).Row End Sub "Paige" wrote in message ... My spreadsheet has 4 columns, for example: Col A B C D Description Type Charge Offering Alert $35 SO Alert SO Alert 9113 SO Perform $ 5 SO Perform $12 SO Perform 9220 SO Alert $19 SCO Alert 8332 SCO AA i/p $23 SO AA i/p SO I need to: 1) Go through each row of Col D; if it says 'SCO', then go to next row of Col D. 2) If it says 'SO', then a) If Col C 0, add the value in Col C to any other value in Col C (going down) until both Col A and Col B are < blank, and put that sum in Col C on the same row where both Col A and Col B are < blank, then erase the individual entries in Col C used to come to that sum. If during this process you ever find that both Col A and B are blank, then stop and go to the next row in Col D, and start over to see if it says 'SO' or 'SCO'. b) If Col C is blank or = 0, then go to the next row of Col D and start over to see if it says 'SO' or 'SCO'. I've struggled with this for quite some time and am desperately hoping someone can help. The final product, using the example above and afer the macro has run, should look like this: Col A B C D Description Type Charge Offering Alert SO Alert SO Alert 9113 $35 SO Perform SO Perform SO Perform 9220 $17 SO Alert $19 SCO Alert 8332 SCO AA i/p $23 SO AA i/p SO |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Complex search, copy, and move opperation. Please HELP!!! | Excel Discussion (Misc queries) | |||
Move names from Search to Excel | Excel Discussion (Misc queries) | |||
Search and move?? | Excel Programming | |||
How do I move data based on a conditional column search? | Excel Programming | |||
Search column and move text formula | Excel Discussion (Misc queries) |