hightlighting rows
Lynn,
I built the procedure in the click event of a command button on sheet 1. By
default it was named Private Sub CommandBUtton1_Click. Get rid of the word
"Private", so that it is called Sub CommandButton1_Click, and it will be seen
from the Macro menu selection.
As far as reporting which names do not match. Do you mean that names in the
text file may not have a match in the work book? This is easy enough to deal
with. Do you want the unmatched names to appear in a list somewhere, and if
so, where? Sheet3? Let me know. If it's just a couple and you want to see a
messagebox list names one at a time, or just to let you know that there were
some unmatched names, please check sheet x, this is all fairly easy to add to
the existing procedure.
I am only guessing at how to read your names file without knowing it's
actual structure. Let me know if actually can read the names properly and if
not, I would need accurate details as to how that file is arranged in a
structural sense? I also gathered from your original post that first and last
names are in the same column. The procedure as a result is only looking at
one column to match up names. Let me know how it works out.
Roy
"Lynn" wrote:
Greg ,
after adding this macro, when i go to tools - macro - macros , i don't see
CommandButton1_Click in the macro list.
how can i add it in the macro so that i can select and run it?
thanks
"Greg Wilson" wrote in message
...
Roy apparently inadvertently got the SETTINGS code out of order on his
repost. The NamesColumn value needs to be defined before running the line:
LastRow = ActiveSheet.Cells(65536, NamesColumn).End(xlUp).Row
Try moving the following code to above the "LastRow =
ActiveSheet(Cells..."
line:
'SETTINGS
NamesColumn = 1 'Set this to column you keep names in
FirstColumn = 1 'Set this to first column to be highlighted
LastColumn = 11 'Set this to last column to be highlighted
'END SETTINGS
Regards,
Greg
"Lynn" wrote:
Hi,
when i run this macro it says:
Run-time error '1004'
Method 'Calculation' of object '_Application' failed
"Roy Wagner" wrote in message
...
As soon as I posted, I noticed an issue whereas if you hit Cancel in
the
File
Open Dialog, the procedure exits without resetting screen updating,
calculation mode and page breaks. Use this rearranged version to avoid
that
inconvenience.
Roy
Private Sub CommandButton1_Click()
'This procedure assumes that your text file contains
'ONLY names, exactly as they appear on your sheet
'The file is opened in sequential mode and commas
'will act as delimiters, in other words the name
'can be stored as "John Smith" or Smith John",
'but not as "Smith, John" or "John, Smith"
'Check the calibration settings below to coordinate
'the procedure to your sheet layout
Dim OriginalPageBreakMode As Boolean
Dim UserFile As String, Customer As String
Dim ThisRow As Long, ThisColumn As Integer, LastRow As Integer
Dim NamesColumn As Integer, FirstColumn As Integer
Dim LastColumn As Integer
Dim NoErrors As Boolean, myBad As Integer
On Error GoTo ErrorHandler
NoErrors = False
LastRow = ActiveSheet.Cells(65536, NamesColumn).End(xlUp).Row 'find
last
occupied row.
UserFile = Application.GetOpenFilename(, , "Select a file to open")
If UserFile = "False" Then Exit Sub
With Application
CalculationMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
OriginalPageBreakMode = .DisplayPageBreaks
.DisplayPageBreaks = False
End With
'SETTINGS
NamesColumn = 1 'Set this to column you keep names in
FirstColumn = 1 'Set this to first column to be highlighted
LastColumn = 11 'Set this to last column to be highlighted
'END SETTINGS
Open UserFile For Input As #1
While Not EOF(1)
Input #1, Customer
For ThisRow = 1 To LastRow
If Cells(ThisRow, NamesColumn).Value = Customer Then
For ThisColumn = FirstColumn To LastColumn
With Cells(ThisRow, ThisColumn)
.Interior.ColorIndex = 6 'Yellow
End With
Next
End If
Next
Wend
NoErrors = True
ErrorHandler:
Close 1
With Application
.Calculation = CalculationMode
.ScreenUpdating = True
End With
ActiveSheet.DisplayPageBreaks = OriginalPageBreakMode
If NoErrors = False Then
myBad = MsgBox("Procedure aborted with errors." & vbLf & vbLf &
"Error"
& Str(Err) & " occurred in " & Err.Source & vbLf & Err.Description,
vbInformation, "Oh No!")
End If
On Error GoTo 0
End Sub
|