S
scott
Below I have a function that finds a string within a range in FindCell()
function. My sub GetDate() finds a cell containing a date just fine, except
if the cell is empty or doesn't exist.
How can I add a test to the "FindCell("To Period",
Sheets(1).Cells).Offset(0, 2)" part to display a simple msgbox if the cell
is empty or doesn't exist?
Sub GetDate()
Dim cell As Range, cellOffset As Range
Dim sDateRange As Date
Set cell = FindCell("To Period", Sheets(1).Cells).Offset(0, 2)
sDateRange = CDate(Right(cell.Value, 2) & "/" & (Left(cell.Value,
Len(cell) - 2)))
End Sub
Function FindCell(searchFor As String, _
searchRange As Range) As Range
With searchRange
Set FindCell = .Find(what:=searchFor, After:=.Cells(.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=True)
End With
End Function
function. My sub GetDate() finds a cell containing a date just fine, except
if the cell is empty or doesn't exist.
How can I add a test to the "FindCell("To Period",
Sheets(1).Cells).Offset(0, 2)" part to display a simple msgbox if the cell
is empty or doesn't exist?
Sub GetDate()
Dim cell As Range, cellOffset As Range
Dim sDateRange As Date
Set cell = FindCell("To Period", Sheets(1).Cells).Offset(0, 2)
sDateRange = CDate(Right(cell.Value, 2) & "/" & (Left(cell.Value,
Len(cell) - 2)))
End Sub
Function FindCell(searchFor As String, _
searchRange As Range) As Range
With searchRange
Set FindCell = .Find(what:=searchFor, After:=.Cells(.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=True)
End With
End Function