Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How can I streamline this repetitious piece of code?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is wrong with this vba piece of code? Jo[_2_] Excel Discussion (Misc queries) 4 October 4th 07 05:01 PM
Super piece of code..At least for me!! Arishy[_2_] Excel Programming 3 August 16th 05 04:20 PM
Streamline copying and pasting code Art Excel Programming 2 May 22nd 04 09:31 PM
Streamline macro code. Pete Excel Programming 1 April 21st 04 02:22 PM
Streamline PivotTable creation code Tod Excel Programming 1 February 9th 04 08:39 PM


All times are GMT +1. The time now is 10:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"