hightlighting rows
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
|