What is the syntax to search a range?

Range("<your range here>").Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)
'What - data to search for; only mandatory parameter
'value (ex) any VBA data type like 123, 12.3, "name"

'After - a single cell to start searching from
'value (ex) Range("A1"), Range("B5")

'LookIn - to search in formulas, values, or comments
'value (ex) xlValues, xlFormulas, xlComments

'LookAt - look at part of cell or entire cell?
'value (ex) xlWhole, xlPart

'SearchOrder - search by rows or columns
'value (ex) xlByRows, xlByColumns

'SearchDirection - search next cell or previous ones
'value (ex) xlNext, xlPrevious

'the following parameter's values are either true or false
'MatchCase - is search case sensitive?
'MatchByte - only relevant if you have installed double-byte language support
'SearchFormat - search by formatting (which is set using Application.FindFormat)

It is critical to note that the Range.Find method does not return a value, rather, it returns a Range object. If nothing is found, the Range object will be Nothing.

'examples

'returns Emily Carn
Range("B3:B20").Find(What:="Emily").Value

'selects cell B8
Range("B3:B20").Find(What:="Emily", MatchCase:=False).Select

'returns 19
Range("B3:B20").Find(What:="Emily", After:=Range("B17")).Row

capture

Advertisements

What is the syntax to change text case?

UCase(<value to be converted to upper case>)
LCase(<value to be converted to lower case>)
‘examples
MsgBox( LCase(“HELLO”)) ‘returns hello
Range (“A1”) = UCase(Range(“A1”))

What is the syntax for Select Case?

Select Case <value>
    Case <value1>
        ‘your code here
    Case <value2>
        ‘your code here

    Case Else
        ‘your code here
End Select
‘example
Select Case userGradeInput ‘userGradeInput is an integer variable
    Case 100
        MsgBox “You got a perfect grade!”
    Case Else
        MsgBox “You did not get a perfect grade.”
End Select