Sunday, March 14, 2010

Check Column Exist in Excel

'Check the column exist in Excel File. In Fnd string pass the Column heading text.

Function CheckColumnExist(Fnd As String) As Boolean
'Check the column exist in Excel File.
CheckColumnExist = False
Set r1 = Cells.Find(What:=Fnd, _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not r1 Is Nothing Then
CheckColumnExist = True
End If
End Function

No comments: