Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Checking for a minimum of 5 rows

I have a procedure that sorts a list of reps by their id and then transaction
amount. Then copies the top 5 transactions to another sheet. The problem is
when a rep has less than 5 transactions it throws off the other spreadsheet
from that point on. I need something that checks to see if the rep has 5
transactions and if he doesn't it tacks on the appropriate amount of "dummy"
transactions to make a total of 5 and then copies those 5 transactions to the
other sheet. How can I do this? Here's the code I have so far:

Sub TallySheetRepDump()
Call BanSumSort
NewRow = 6
With Sheets("Catalyst Dump")
'The following line of code calculates the number of rows of data
LastRow = .Range("B" & Rows.Count).End(xlUp).Row
'Sort by UID (column A) then by Transaction Amount (column F)
.Rows("2:" & LastRow).Sort _
Key1:=.Range("A2"), _
Order1:=xlAscending, _
Key2:=.Range("F2"), _
Order2:=xlAscending, _
Header:=xlNo

Start = 1
NewRow = 6
'Outer loop for entire worksheet. There is an error here if the
'rep doesn't have 5 or more adjustments in Catalyst Dump
For RowCount = Start To LastRow
'Check to see if RowCount is equal to the next row. If not that
'means the name has changed and we want to capture the info for
'the current rep
If .Range("A" & RowCount) < .Range("A" & (RowCount + 1)) Then
'If name changes make sure the rep has 5 or more transactions
StartRow = RowCount + 1
RowCount = RowCount + 5
'If rep has at least 5 transactions then copy the first 5 and
'move them to the Tally Sheet
If .Range("A" & StartRow) = .Range("A" & RowCount) Then
.Range("A" & StartRow & ":F" & RowCount).Copy _
Destination:=Sheets("Tally Sheet").Range("A" & NewRow)
.Range("G" & StartRow & ":Q" & RowCount).Copy _
Destination:=Sheets("Tally Sheet").Range("N" & NewRow)
NewRow = NewRow + 8
Else
'this is where I need something that inserts "dummy"
transactions
'to give the rep a total of 5 and then copy to the other sheet
End If
End If
Next RowCount
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Checking for a minimum of 5 rows

Hi

Try this:

....
If .Range("A" & StartRow) = .Range("A" & RowCount) Then
.Range("A" & StartRow & ":F" & RowCount).Copy _
Destination:=Sheets("Tally Sheet").Range("A" &
NewRow)
.Range("G" & StartRow & ":Q" & RowCount).Copy _
Destination:=Sheets("Tally Sheet").Range("N" &
NewRow)
NewRow = NewRow + 8
Else
For counter = 1 To 4
If .Range("A" & StartRow) < .Range("A" & counter)
Then
counter = counter - 1
.Range("A" & StartRow & ":F" & counter).Copy _
Destination:=Sheets("Tally Sheet").Range
("A" & NewRow)
.Range("G" & StartRow & ":Q" & counter).Copy _
Destination:=Sheets("Tally Sheet").Range
("N" & NewRow)
NewRow = NewRow + 8
Exit For
End If
Next
End If

Hopes this helps:

---
Per

On 21 Apr., 18:53, Bishop wrote:
I have a procedure that sorts a list of reps by their id and then transaction
amount. *Then copies the top 5 transactions to another sheet. *The problem is
when a rep has less than 5 transactions it throws off the other spreadsheet
from that point on. *I need something that checks to see if the rep has 5
transactions and if he doesn't it tacks on the appropriate amount of "dummy"
transactions to make a total of 5 and then copies those 5 transactions to the
other sheet. *How can I do this? *Here's the code I have so far:

Sub TallySheetRepDump()
* *Call BanSumSort
* *NewRow = 6
* *With Sheets("Catalyst Dump")
* * * 'The following line of code calculates the number of rows of data
* * * LastRow = .Range("B" & Rows.Count).End(xlUp).Row
* * * 'Sort by UID (column A) then by Transaction Amount (column F)
* * * .Rows("2:" & LastRow).Sort _
* * * * *Key1:=.Range("A2"), _
* * * * *Order1:=xlAscending, _
* * * * *Key2:=.Range("F2"), _
* * * * *Order2:=xlAscending, _
* * * * *Header:=xlNo

* * * Start = 1
* * * NewRow = 6
* * * 'Outer loop for entire worksheet. *There is an error here if the
* * * 'rep doesn't have 5 or more adjustments in Catalyst Dump
* * * For RowCount = Start To LastRow
* * * * *'Check to see if RowCount is equal to the next row. *If not that
* * * * *'means the name has changed and we want to capture the info for
* * * * *'the current rep
* * * * *If .Range("A" & RowCount) < .Range("A" & (RowCount + 1)) Then
* * * * * * 'If name changes make sure the rep has 5 or more transactions
* * * * * * StartRow = RowCount + 1
* * * * * * RowCount = RowCount + 5
* * * * * * 'If rep has at least 5 transactions then copy the first 5 and
* * * * * * 'move them to the Tally Sheet
* * * * * * If .Range("A" & StartRow) = .Range("A" & RowCount) Then
* * * * * * * * .Range("A" & StartRow & ":F" & RowCount).Copy _
* * * * * * * * * *Destination:=Sheets("Tally Sheet").Range("A" & NewRow)
* * * * * * * * .Range("G" & StartRow & ":Q" & RowCount).Copy _
* * * * * * * * * *Destination:=Sheets("Tally Sheet").Range("N" & NewRow)
* * * * * * * * NewRow = NewRow + 8
* * * * * * Else
* * * * * * * * 'this is where I need something that inserts "dummy"
transactions
* * * * * * * * 'to give the rep a total of 5 and then copy to the other sheet
* * * * * * End If * * * *
* * * * End If
* * * Next RowCount
* *End With


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Checking for a minimum of 5 rows

For counter = 1 To 4
If .Range("A" & StartRow) < .Range("A" & counter) Then

If StartRow = 5 and I need to compare A5 with A6 that just compares A5 with A1

"Per Jessen" wrote:

Hi

Try this:

....
If .Range("A" & StartRow) = .Range("A" & RowCount) Then
.Range("A" & StartRow & ":F" & RowCount).Copy _
Destination:=Sheets("Tally Sheet").Range("A" &
NewRow)
.Range("G" & StartRow & ":Q" & RowCount).Copy _
Destination:=Sheets("Tally Sheet").Range("N" &
NewRow)
NewRow = NewRow + 8
Else
For counter = 1 To 4
If .Range("A" & StartRow) < .Range("A" & counter)
Then
counter = counter - 1
.Range("A" & StartRow & ":F" & counter).Copy _
Destination:=Sheets("Tally Sheet").Range
("A" & NewRow)
.Range("G" & StartRow & ":Q" & counter).Copy _
Destination:=Sheets("Tally Sheet").Range
("N" & NewRow)
NewRow = NewRow + 8
Exit For
End If
Next
End If

Hopes this helps:

---
Per

On 21 Apr., 18:53, Bishop wrote:
I have a procedure that sorts a list of reps by their id and then transaction
amount. Then copies the top 5 transactions to another sheet. The problem is
when a rep has less than 5 transactions it throws off the other spreadsheet
from that point on. I need something that checks to see if the rep has 5
transactions and if he doesn't it tacks on the appropriate amount of "dummy"
transactions to make a total of 5 and then copies those 5 transactions to the
other sheet. How can I do this? Here's the code I have so far:

Sub TallySheetRepDump()
Call BanSumSort
NewRow = 6
With Sheets("Catalyst Dump")
'The following line of code calculates the number of rows of data
LastRow = .Range("B" & Rows.Count).End(xlUp).Row
'Sort by UID (column A) then by Transaction Amount (column F)
.Rows("2:" & LastRow).Sort _
Key1:=.Range("A2"), _
Order1:=xlAscending, _
Key2:=.Range("F2"), _
Order2:=xlAscending, _
Header:=xlNo

Start = 1
NewRow = 6
'Outer loop for entire worksheet. There is an error here if the
'rep doesn't have 5 or more adjustments in Catalyst Dump
For RowCount = Start To LastRow
'Check to see if RowCount is equal to the next row. If not that
'means the name has changed and we want to capture the info for
'the current rep
If .Range("A" & RowCount) < .Range("A" & (RowCount + 1)) Then
'If name changes make sure the rep has 5 or more transactions
StartRow = RowCount + 1
RowCount = RowCount + 5
'If rep has at least 5 transactions then copy the first 5 and
'move them to the Tally Sheet
If .Range("A" & StartRow) = .Range("A" & RowCount) Then
.Range("A" & StartRow & ":F" & RowCount).Copy _
Destination:=Sheets("Tally Sheet").Range("A" & NewRow)
.Range("G" & StartRow & ":Q" & RowCount).Copy _
Destination:=Sheets("Tally Sheet").Range("N" & NewRow)
NewRow = NewRow + 8
Else
'this is where I need something that inserts "dummy"
transactions
'to give the rep a total of 5 and then copy to the other sheet
End If
End If
Next RowCount
End With



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
Checking for duplication on rows Karmen New Users to Excel 2 February 8th 06 05:22 AM
Checking Blank Rows AccessHelp Excel Programming 4 January 16th 06 03:42 PM
minimum along rows [email protected] Excel Worksheet Functions 12 August 25th 05 02:15 PM
Finding the minimum in a selected number of rows of the same colum Mark Rugers Excel Worksheet Functions 5 July 20th 05 10:37 PM
Finding minimum value across selected rows of an array Dazed and confused about min, max Excel Worksheet Functions 2 February 25th 05 11:11 PM


All times are GMT +1. The time now is 07:49 AM.

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

About Us

"It's about Microsoft Excel"