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

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
______________________________________________

Sub Separate_Sales()
Application.ScreenUpdating = False

' separates sales $5000
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 5000 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

' separates sales $10000
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 10000 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

' separates sales $25000
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 25000 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

' separates sales $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 50000 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
 
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 11:18 AM.

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"