Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default select entire rows using a contains comparison - an example

No question here, just an example procedure for the archive.

Select entire rows based on a selection using a "contains"
comparision operation.


Sub SelectRowsByContains()

'Evaluates for a prompted value to see if the value is
'contained in any of the cells in selection,
'If value is present in the cell, the whole row for that cell or cells
is selected.

Dim cell, ContainsRange As Range
On Error Resume Next
EvalValue = Application.InputBox(prompt:="Enter the value you wish
to evaluate for in each cell in selection. This value will be evaluated
to see if it is contained in each cell.", Title:="Select Rows Based on
a Single Column", _
Default:="yourvaluehere", Type:=1
+ 2) 'type 1 is number

If EvalValue = False Then Exit Sub

For Each cell In Selection

''******** Case-sensitive evaluation ***********

If cell.Value Like "*" & EvalValue & "*" = True Then

If ContainsRange Is Nothing Then
Set ContainsRange = cell
Else
Set ContainsRange = Union(cell, ContainsRange)
End If

End If


''******** No case-sensitive evaluation ***********

' If UCase(cell.Value) Like "*" & UCase(EvalValue) & "*"
= True Then
'
' If ContainsRange Is Nothing Then
' Set ContainsRange = cell
' Else
' Set ContainsRange = Union(cell, ContainsRange)
' End If
'
' End If

Next cell

'Test for a valid range result:
If Not ContainsRange Is Nothing Then
ContainsRange.Select

Selection.EntireRow.Select ' Turn this line on/off for whole
row selection preference
Else
MsgBox "The value you entered was not contained in any cell in
the selection"

End If


End Sub

select rows based on a selection using a contains function
contains function comparision contains comparison

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
Use find to select entire rows with a cell with that value Franky88 Excel Worksheet Functions 2 March 30th 07 06:38 PM
Select the entire row shantanu oak Excel Discussion (Misc queries) 5 July 17th 06 11:34 AM
select cell rather selecting entire row ilyaskazi[_99_] Excel Programming 1 November 25th 05 02:48 PM
Using SELECT...CASE with comparison operators? Toby Erkson[_3_] Excel Programming 7 July 14th 04 09:52 PM
How to select entire column using VBA Phill Excel Programming 3 December 5th 03 03:44 PM


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