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: 38
Default Combining Procedures into Loop

I'd like to combine the following three nearly identical procedures
into one that would loop through the three of them.
2010/09, 2010/10, 2010/11 are in A1:A3 on Sheet2 so they could be
referenced rather than hard coded.


Private Sub CountErrorLoans201009()
Dim cell As Range
Dim xCount As Integer
Dim LoanNumber As String
Dim Errors As String

For Each cell In Sheets("Data").Range("LoanNumbers")

If cell.Value = LoanNumber And _
cell.Offset(0, 1).Value = Errors Then GoTo skipcell
LoanNumber = cell.Value
Errors = cell.Offset(0, 1).Value

If cell.Offset(0, 2).Value = "2010/09" And _
cell.Offset(0, 1).Value = "Error" Then
xCount = xCount + 1
End If
skipcell:
Next cell
Sheets("Sheet2").Range("b1").Value = xCount
xCount = 0
End Sub

Private Sub CountErrorLoans201010()
Dim cell As Range
Dim xCount As Integer
Dim LoanNumber As String
Dim Errors As String

For Each cell In Sheets("Data").Range("LoanNumbers")

If cell.Value = LoanNumber And _
cell.Offset(0, 1).Value = Errors Then GoTo skipcell
LoanNumber = cell.Value
Errors = cell.Offset(0, 1).Value

If cell.Offset(0, 2).Value = "2010/10" And _
cell.Offset(0, 1).Value = "Error" Then
xCount = xCount + 1
End If
skipcell:
Next cell
Sheets("Sheet2").Range("b2").Value = xCount
xCount = 0
End Sub

Private Sub CountErrorLoans201011()
Dim cell As Range
Dim xCount As Integer
Dim LoanNumber As String
Dim Errors As String

For Each cell In Sheets("Data").Range("LoanNumbers")

If cell.Value = LoanNumber And _
cell.Offset(0, 1).Value = Errors Then GoTo skipcell
LoanNumber = cell.Value
Errors = cell.Offset(0, 1).Value

If cell.Offset(0, 2).Value = "2010/11" And _
cell.Offset(0, 1).Value = "Error" Then
xCount = xCount + 1
End If
skipcell:
Next cell
Sheets("Sheet2").Range("b3").Value = xCount
xCount = 0
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
my VBA procedures stopped calling other procedures in excel 2007. Alan in Toronto Excel Programming 2 July 22nd 09 07:32 PM
Get VBA procedures from DB Hiran de Silva[_2_] Excel Programming 3 July 4th 06 05:46 PM
Newbie Q: Error handling procedures in a loop KR Excel Programming 2 March 4th 05 05:51 PM
VBA Sub procedures lexiez Excel Programming 2 October 4th 04 04:21 PM
ListBox Procedures Rockee052[_48_] Excel Programming 1 February 20th 04 09:20 AM


All times are GMT +1. The time now is 11:49 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"