Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for the speedy reply Tom, but I'm not quite sure what
to do with your code. I think the first 3 lines go at the top of my code, and I change 5000 to valtoCheckAgainst, but where in my code should I place the exit for, end if, and Next please? Thanks, Norm __________________________________________________ __ varr = array(5000,10000,25000,50000) for i = lbound(varr) to ubound(varr) valtoCheckAgainst = varr(i) if something < valtoCheckAgainst then exit for end if Next __________________________________________________ _ Sub Separate_Sales() Application.ScreenUpdating = False varr = array(5000,10000,25000,50000) for i = lbound(varr) to ubound(varr) valtoCheckAgainst = varr(i) ' separates sales into <$5000, <$1000, <$25000, <$50000 Range("G1").Select Selection.EntireColumn.Clear Range("F65356").Select Selection.End(xlUp).Select ActiveCell.Offset(0, 1).Select Do Until ActiveCell.Row = 1 If ActiveCell.Offset(0, -1).Value < valtoCheckAgainst Then ActiveCell.Value = 1 End If ActiveCell.Offset(-1, 0).Select Loop Range("H1").Select Selection.EntireColumn.Clear Range("F65356").Select Selection.End(xlUp).Select ActiveCell.Offset(0, 2).Select Do Until ActiveCell.Row = 1 If ActiveCell.Offset(-1, -1) = 1 And ActiveCell.Offset(0, -1) = "" Then ActiveCell.Value = 1 End If ActiveCell.Offset(-1, 0).Select Loop Range("H65356").Select Selection.End(xlUp).Select Do Until ActiveCell.Row = 1 If ActiveCell.Value = 1 Then ActiveCell.EntireRow.Insert ActiveCell.EntireRow.Insert End If ActiveCell.Offset(-1, 0).Select Loop Range("G:H").Select Selection.EntireColumn.Clear End Sub On Wed, 29 Mar 2006 10:02:01 -0800, Tom Ogilvy wrote: varr = array(5000,10000,25000,50000) for i = lbound(varr) to ubound(varr) valtoCheckAgainst = varr(i) if something < valtoCheckAgainst then exit for end if Next -- Regards, Tom Ogilvy "Father Guido" wrote: You'll note that 95% of the code is repeated with just a single change per section. I simply change the comparator to evaluate the data 4 times as shown below. 5000 10000 25000 50000 How can I streamline this code to use a loop and change the comparator value to each of the 4 values above, rather than repeating the entire code 4 times with one change each? Thanks!!! Norm |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
What is wrong with this vba piece of code? | Excel Discussion (Misc queries) | |||
Super piece of code..At least for me!! | Excel Programming | |||
Streamline copying and pasting code | Excel Programming | |||
Streamline macro code. | Excel Programming | |||
Streamline PivotTable creation code | Excel Programming |