colFare = Cells.Find(what:="Vendor Fare", after:=Cells(1, 1), lookat:=xlWhole).Column
Option Explicit
Sub FindFare()
'This routine loops through a column of values and counts the number of errors in the column
Dim rowHeader As Integer
Dim colFare As Integer
Dim rowActive As Integer
Dim ErrCount As Integer
rowHeader = Cells.Find(what:="Client_Code", after:=Cells(1, 1), lookat:=xlWhole).Row
'colFare = 13
colFare = Cells.Find(what:="Vendor Fare", after:=Cells(1, 1), lookat:=xlWhole).Column
rowActive = rowHeader
'Count Errors
ErrCount = 0
'Loop through data
Do Until Cells(rowActive, colFare) = ""
If Cells(rowActive, colFare) Like "Err?*" Then
ErrCount = ErrCount + 1
End If
rowActive = rowActive + 1
Loop
Debug.Print ErrCount
End Sub
I am sure there is a simple explanation, but I am blind to it... Can anyone enlighten me, please?ASKER
Sub FindFare()
'This routine loops through a column of values and counts the number of errors in the column
Dim rowHeader As Integer
Dim colFare As Integer
Dim rowActive As Integer
Dim ErrCount As Integer
Dim cCell As Range
'-------
'Idenitfy Header Row and Relevant Column
Set cCell = Cells.Find(what:="Client_Code", after:=Cells(1, 1), lookat:=xlWhole)
If Not cCell Is Nothing Then
rowHeader = cCell.Row
Else
MsgBox ("Please check your header it should be 'Client_Code' routine will exit")
Exit Sub
End If
'colFare = 13
Set cCell = Cells.Find(what:="Vendor Fare", after:=Cells(1, 1), lookat:=xlWhole)
If Not cCell Is Nothing Then
colFare = cCell.Column
Else
MsgBox ("Please check your header it should be 'Vendor Fare' routine will exit")
Exit Sub
End If
'Set active row for Loop
rowActive = rowHeader
'-------
'Count Errors
ErrCount = 0
'Loop through data
Do Until Cells(rowActive, colFare) = ""
If Cells(rowActive, colFare) Like "Err?*" Then
ErrCount = ErrCount + 1
End If
rowActive = rowActive + 1
Loop
'-------
'Print the error count
Debug.Print ErrCount
End Sub
ASKER
ASKER
ASKER
The problem, as I see it, is that if the machine is mistakenly causing an error, then it does not matter how many messages are generated, if the solution is not a solution. Does that make sense?
ASKER
ASKER
ASKER
Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.
TRUSTED BY
That's because the Find returns Nothing, and Nothing.Column doesn't make sense.