viernes, 10 de febrero de 2012

VBA - EXCEL MACRO (BUSCAR FECHA)


  'VBA MACRO EXCEL  -  APPLICATION EXCEL MATH FUNCTION
  'BUSCAR FECHA VBA MATCH EXCEL - FIND DATE EXCEL RANGE
  'MEDIANTE ESTA MACRO RETORNARA LA FECHA BUSCADA EN UN RANGO DE  CELDAS SELECCIONADAS

  Sub MatchBuscarFecha()

       Dim TheDate As Date
       Dim Index As Variant

       TheDate = #1/1/2000#

  'Hallar el item entre la colección de celdas.....trabaja igual buscando entre los elementos de
 'un array el primer argumento es el elemento a buscar "dato" , el segundo argumento sera el array de datos()

'Aqui asigno como segundo argumento la seleccion de celdas
' pero podrias colocar cualquier rango --> Range("A1:A500") por ejemplo

       Index = Application.Match(CLng(TheDate), Selection, 0)
.
       'Mostrar el dato encontrado si existe

       If IsError(Index) Then
           MsgBox "No encontrado"
       Else
           MsgBox "item: " & Index & " celda : " & Selection.Cells(Index).Address
       End If

   End Sub